private void Receiver_RequiredInputChanged(MyPowerReceiver changedConsumer, float oldRequirement, float newRequirement)
        {
            if (m_needsRecompute)
            {
                RecomputePowerDistribution();
            }

            // Go over all priorities, starting from the changedConsumer.
            int idx = (int)changedConsumer.Group;

            MyDebug.AssertDebug(m_consumerDataByPriority[idx].RequiredInput >= 0.0f);
            m_consumerDataByPriority[idx].RequiredInput = 0.0f;
            foreach (var consumer in m_consumersByPriority[idx])
            {
                m_consumerDataByPriority[idx].RequiredInput += consumer.PowerReceiver.RequiredInput;
            }

            // Update cumulative requirements.
            float cumulative = (idx != 0) ? m_consumerDataByPriority[idx - 1].RequiredInputCumulative
                                          : 0.0f;

            for (int i = idx; i < m_consumerDataByPriority.Length; ++i)
            {
                cumulative += m_consumerDataByPriority[i].RequiredInput;
                m_consumerDataByPriority[i].RequiredInputCumulative = cumulative;
            }

            RecomputePowerDistributionPartial(idx, m_consumerDataByPriority[idx].AvailablePower);
            MyDebug.AssertDebug(m_consumerDataByPriority[idx].RequiredInput >= 0.0f);
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            m_cameraDummy = Matrix.Identity;
            m_characterDummy = Matrix.Identity;

            base.Init(objectBuilder, cubeGrid);

            var chamberOb = objectBuilder as MyObjectBuilder_CryoChamber;

            if (chamberOb.SteamId != null && chamberOb.SerialId != null)
            {
                m_currentPlayerId = new MyPlayer.PlayerId(chamberOb.SteamId.Value, chamberOb.SerialId.Value);
            }
            else
            {
                m_currentPlayerId = null;
            }

            var overlayTexture = BlockDefinition.OverlayTexture;
            if (!string.IsNullOrEmpty(overlayTexture))
            {
                m_overlayTextureName = overlayTexture;
            }

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.IdlePowerConsumption,
                this.CalculateRequiredPowerInput);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;

            NeedsUpdate |= Common.MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
Beispiel #3
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            if (Physics != null)
            {
                Physics.Close();
            }

            var detectorShape = new HkBoxShape(new Vector3(cubeGrid.GridSize / 3.0f));
            var massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(detectorShape.HalfExtents, BlockDefinition.VirtualMass);
            Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
            Physics.IsPhantom = false;
            Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.VirtualMassLayer);
            Physics.Enabled = IsWorking && cubeGrid.Physics != null && cubeGrid.Physics.Enabled;
            Physics.RigidBody.Activate();
            detectorShape.Base.RemoveReference();

            UpdateText();

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

        }
Beispiel #4
0
        public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_CubeBlock objectBuilder, Sandbox.Game.Entities.MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            m_oxygenFarmDefinition = BlockDefinition as MyOxygenFarmDefinition;
            IsWorkingChanged += OnIsWorkingChanged;
            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            InitializeConveyorEndpoint();

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                m_oxygenFarmDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            GameLogic = new MySolarGameLogicComponent();
            m_solarComponent = GameLogic as MySolarGameLogicComponent;

            m_solarComponent.Initialize(m_oxygenFarmDefinition.PanelOrientation, m_oxygenFarmDefinition.IsTwoSided, m_oxygenFarmDefinition.PanelOffset, this);

            AddDebugRenderComponent(new Components.MyDebugRenderComponentSolarPanel(this));
        }
 public MyGridGyroSystem(MyCubeGrid grid)
 {
     m_grid = grid;
     m_gyros = new HashSet<MyGyro>();
     m_gyrosChanged = false;
     PowerReceiver = new MyPowerReceiver(
         MyConsumerGroupEnum.Gyro,
         true,
         m_maxRequiredPowerInput,
         () => m_maxRequiredPowerInput);
     PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
 }
        public MyGridWheelSystem(MyCubeGrid grid)
        {
            m_wheels = new HashSet<MyMotorSuspension>();
            m_wheelsChanged = false;
            m_grid = grid;
            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                m_maxRequiredPowerInput,
                () => m_maxRequiredPowerInput);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;

            grid.OnPhysicsChanged += grid_OnPhysicsChanged;
        }
        public MyGridConveyorSystem(MyCubeGrid grid)
        {
            m_grid = grid;

            m_lineEndpoints = null;
            m_linePoints = null;
            m_deserializedLines = null;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Conveyors,
                false,
                CONVEYOR_SYSTEM_CONSUMPTION,
                () => CalculateConsumption());

            PowerReceiver.Update();
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
        }
Beispiel #8
0
        public void Init(MyObjectBuilder_Battery builder)
        {
            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Charging,
                true,
                MyEnergyConstants.BATTERY_MAX_POWER_INPUT,
                () => (RemainingCapacity < MyEnergyConstants.BATTERY_MAX_CAPACITY) ? MyEnergyConstants.BATTERY_MAX_POWER_INPUT : 0f);
            PowerReceiver.Update();

            if (builder != null)
            {
                (this as IMyPowerProducer).Enabled = builder.ProducerEnabled;
                if (MySession.Static.SurvivalMode)
                {
                    RemainingCapacity = MathHelper.Clamp(builder.CurrentCapacity, 0f, MyEnergyConstants.BATTERY_MAX_CAPACITY);
                }
            }
            RefreshHasRemainingCapacity();
        }
Beispiel #9
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            var def = BlockDefinition as MyCargoContainerDefinition;
            var ob = objectBuilder as MyObjectBuilder_Collector;
            m_inventory = new MyInventory(def.InventorySize.Volume, def.InventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Init(ob.Inventory);
            m_inventory.ContentsChanged += Inventory_ContentChangedCallback;
            if (Sync.IsServer && CubeGrid.CreatePhysics)
                LoadDummies();
            PowerReceiver = new MyPowerReceiver(
                group: MyConsumerGroupEnum.Conveyors,
                isAdaptible: false,
                maxRequiredInput: MyEnergyConstants.MAX_REQUIRED_POWER_COLLECTOR,
                requiredInputFunc: () => base.CheckIsWorking() ? PowerReceiver.MaxRequiredInput : 0f);
            PowerReceiver.Update();
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(PowerReceiver,this));

            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            m_useConveyorSystem = ob.UseConveyorSystem;
        }
Beispiel #10
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            if (BlockDefinition is MyMedicalRoomDefinition)
            {
                var def = (MyMedicalRoomDefinition)BlockDefinition;
                m_idleSound = new MySoundPair(def.IdleSound);
                m_progressSound = new MySoundPair(def.ProgressSound);
            }
            else
            {
                m_idleSound = new MySoundPair("BlockMedical");
                m_progressSound = new MySoundPair("BlockMedicalProgress");
            }

            m_rechargeSocket = new MyRechargeSocket();

            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            SteamUserId = (objectBuilder as MyObjectBuilder_MedicalRoom).SteamUserId;

            if (SteamUserId != 0) //backward compatibility
            {
                MyPlayer controller = Sync.Players.TryGetPlayerById(new MyPlayer.PlayerId(SteamUserId));
                if (controller != null)
                {
                    IDModule.Owner = controller.Identity.IdentityId;
                    IDModule.ShareMode = MyOwnershipShareModeEnum.Faction;
                }
            }
            SteamUserId = 0;

            m_takeSpawneeOwnership = (objectBuilder as MyObjectBuilder_MedicalRoom).TakeOwnership;
            m_setFactionToSpawnee = (objectBuilder as MyObjectBuilder_MedicalRoom).SetFaction;

            SyncObject = new SyncClass(this);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            InitializeConveyorEndpoint();

            PowerReceiver = new MyPowerReceiver(
                group: MyConsumerGroupEnum.Utility,
                isAdaptible: false,
                maxRequiredInput: MyEnergyConstants.MAX_REQUIRED_POWER_MEDICAL_ROOM,
                requiredInputFunc: () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();
            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(PowerReceiver, this));

            if (this.CubeGrid.CreatePhysics)
                Components.Add<MyRespawnComponent>(new MyRespawnComponent());
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_ShipConnector;
            Vector3 inventorySize = (BlockDefinition.Size * CubeGrid.GridSize) * 0.8f; // 0.8 ~= 0.5^(1/3) to make the inventory volume approx. one half of the block size
            m_inventory = new MyInventory(inventorySize.Volume, inventorySize, MyInventoryFlags.CanReceive | MyInventoryFlags.CanSend, this);
            m_inventory.Init(ob.Inventory);
            m_throwOut = ob.ThrowOut;
            m_collectAll = ob.CollectAll;

            SlimBlock.DeformationRatio = ob.DeformationRatio;

            float consumption = MyEnergyConstants.MAX_REQUIRED_POWER_CONNECTOR;
            if (cubeGrid.GridSizeEnum == MyCubeSize.Small)
            {
                consumption *= 0.01f;
            }

            m_receiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Conveyors,
                false,
                consumption,
                () => base.CheckIsWorking() ? PowerReceiver.MaxRequiredInput : 0f
            );
            PowerReceiver.Update();
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;

            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            
            if(CubeGrid.CreatePhysics)
                LoadDummies();
            if (Physics != null) Physics.Enabled = true;
            if (m_connectorDummy != null)
            {
                m_connectorDummy.Enabled = true;
            }

            if (ob.ConnectedEntityId != 0) 
            {
                m_previouslyConnected = ob.Connected;
                m_previouslyConnectedEntityId = ob.ConnectedEntityId;
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }

            IsWorkingChanged += MyShipConnector_IsWorkingChanged;

            AddDebugRenderComponent(new Components.MyDebugRenderCompoonentShipConnector(this));
        }
Beispiel #12
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            if (!MyFakes.ENABLE_PROJECTOR_BLOCK)
            {
                return;
            }

            var projectorBuilder = (MyObjectBuilder_Projector)objectBuilder;
            if (projectorBuilder.ProjectedGrid != null)
            {
                m_projectionOffset = projectorBuilder.ProjectionOffset;
                m_projectionRotation = projectorBuilder.ProjectionRotation;

                m_savedProjection = projectorBuilder.ProjectedGrid;
                m_keepProjection = projectorBuilder.KeepProjection;
            }

            m_showOnlyBuildable = projectorBuilder.ShowOnlyBuildable;
            m_instantBuildingEnabled = projectorBuilder.InstantBuildingEnabled;
            m_maxNumberOfProjections = projectorBuilder.MaxNumberOfProjections;
            m_maxNumberOfBlocksPerProjection = projectorBuilder.MaxNumberOfBlocks;
            m_getOwnershipFromProjector = projectorBuilder.GetOwnershipFromProjector;

            m_projectionsRemaining = MathHelper.Clamp(projectorBuilder.ProjectionsRemaining, 0, m_maxNumberOfProjections);

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);

            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            IsWorkingChanged += MyProjector_IsWorkingChanged;

            PowerReceiver.Update();
            m_statsDirty = true;
            UpdateText();

            SyncObject = new MySyncProjector(this);

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            CubeGrid.OnBlockAdded += previewGrid_OnBlockAdded;
            CubeGrid.OnBlockRemoved += previewGrid_OnBlockRemoved;

            CubeGrid.OnGridSplit += CubeGrid_OnGridSplit;
        }
        //[TerminalValues(MySpaceTexts.SwitchText_On, MySpaceTexts.SwitchText_Off)]
        //[Terminal(2, MyPropertyDisplayEnum.Switch, MySpaceTexts.Terminal_UseConveyorSystem, MySpaceTexts.Blank)]
        //[Obfuscation(Feature = Obfuscator.NoRename, Exclude = true)]
        //public MyStringId UseConveyorSystemGui
        //{
        //    get { return m_useConveyorSystem ? MySpaceTexts.SwitchText_On : MySpaceTexts.SwitchText_Off; }
        //    set
        //    {
        //        if (m_useConveyorSystem != (value == MySpaceTexts.SwitchText_On))
        //        {
        //            m_useConveyorSystem = (value == MySpaceTexts.SwitchText_On);
        //            OnPropertiesChanged();
        //        }
        //    }
        //}
        //[TerminalValueSetter(2)]
        //public void RequestUseConveyorSystemChange(MyStringId newVal)
        //{
        //    MySyncConveyors.SendChangeUseConveyorSystemRequest(EntityId, newVal == MySpaceTexts.SwitchText_On);
        //}

        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            var ob = builder as MyObjectBuilder_SmallMissileLauncher;
           
            m_gunBase = new MyGunBase();
   
            var weaponBlockDefinition = BlockDefinition as MyWeaponBlockDefinition;
            if (weaponBlockDefinition != null)
            {
                m_ammoInventory = new MyInventory(weaponBlockDefinition.InventoryMaxVolume, new Vector3(1.2f, 0.98f, 0.98f), MyInventoryFlags.CanReceive, this);
            }
            else
            {
                if (cubeGrid.GridSizeEnum == MyCubeSize.Small)
                    m_ammoInventory = new MyInventory(240.0f / 1000, new Vector3(1.2f, 0.45f, 0.45f), MyInventoryFlags.CanReceive, this); // 4 missiles
                else
                    m_ammoInventory = new MyInventory(1140.0f / 1000, new Vector3(1.2f, 0.98f, 0.98f), MyInventoryFlags.CanReceive, this); // 19 missiles
            }

            base.Init(builder, cubeGrid);

            m_ammoInventory.Init(ob.Inventory);
            m_gunBase.Init(ob.GunBase, BlockDefinition, this);

            m_ammoInventory.ContentsChanged += m_ammoInventory_ContentsChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Defense, 
                false, 
                MyEnergyConstants.MAX_REQUIRED_POWER_SHIP_GUN, 
                () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0.0f);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

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

            m_useConveyorSystem = ob.UseConveyorSystem;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            LoadDummies();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
Beispiel #14
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                PistonDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0.0f);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            var ob = objectBuilder as MyObjectBuilder_PistonBase;
            Velocity = ob.Velocity * BlockDefinition.MaxVelocity;
            MaxLimit = ob.MaxLimit.HasValue ? Math.Min(DenormalizeDistance(ob.MaxLimit.Value), BlockDefinition.Maximum) : BlockDefinition.Maximum;
            MinLimit = ob.MinLimit.HasValue ? Math.Max(DenormalizeDistance(ob.MinLimit.Value), BlockDefinition.Minimum) : BlockDefinition.Minimum;
            m_topBlockId = ob.TopBlockId;
            m_currentPos = ob.CurrentPosition;

            CubeGrid.OnPhysicsChanged += CubeGrid_OnPhysicsChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
 protected void Receiver_RequiredInputChanged(MyPowerReceiver receiver, float oldRequirement, float newRequirement)
 {
     UpdateText();
 }
        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();
        }
        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 |= Common.MyEntityUpdateEnum.EACH_100TH_FRAME | Common.MyEntityUpdateEnum.EACH_10TH_FRAME;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Conveyors,
                false,
                BlockDefinition.PowerInput,
                UpdatePowerInput);
            PowerReceiver.IsPoweredChanged += IsPoweredChanged;
            PowerReceiver.Update();
            UpdateText();
        }
Beispiel #18
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            base.Init(builder, cubeGrid);

            //m_subpartsSize = 0.5f * (0.5f * SlimBlock.CubeGrid.GridSize - 0.3f);

            if (BlockDefinition is MyDoorDefinition)
            {
                var doorDefinition = (MyDoorDefinition)BlockDefinition;
                MaxOpen = doorDefinition.MaxOpen;
                m_openSound = new MySoundPair(doorDefinition.OpenSound);
                m_closeSound = new MySoundPair(doorDefinition.CloseSound);
            }
            else
            {
                MaxOpen = 1.2f;
                m_openSound = new MySoundPair("BlockDoorSmallOpen");
                m_closeSound = new MySoundPair("BlockDoorSmallClose");
            }

            var ob = (MyObjectBuilder_Door)builder;
            m_open = ob.State;
            m_currOpening = ob.Opening;

            PowerReceiver = new MyPowerReceiver(MyConsumerGroupEnum.Doors,
                false,
                MyEnergyConstants.MAX_REQUIRED_POWER_DOOR,
                () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            if (!Enabled || !PowerReceiver.IsPowered)
                UpdateSlidingDoorsPosition(true);

            OnStateChange();

            if (m_open)
            {
                // required when reinitializing a door after the armor beneath it is destroyed
                if (Open && (m_currOpening == MaxOpen))
                    UpdateSlidingDoorsPosition(true);
            }

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Beispiel #19
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_SoundBlock)objectBuilder;

            Volume = builder.Volume;
            Range = builder.Range;
            LoopPeriod = builder.LoopPeriod;
            InitCue(builder.CueName);

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                MyEnergyConstants.MAX_REQUIRED_POWER_SOUNDBLOCK,
                UpdateRequiredPowerInput);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_TextPanel ob = (MyObjectBuilder_TextPanel)objectBuilder;

            PrivateTitle.Append(ob.Title);
            PrivateDescription.Append(ob.Description);
            PublicDescription.Append(ob.PublicDescription);
            PublicTitle.Append(ob.PublicTitle);

            m_currentPos = ob.CurrentShownTexture;
            m_accessFlag = ob.AccessFlag;

            if (Sync.IsServer && Sync.Clients != null)
            {
                Sync.Clients.ClientRemoved += TextPanel_ClientRemoved;
            }

            FontColor = ob.FontColor;
            BackgroundColor = ob.BackgroundColor;
            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
            Render.NeedsDrawFromParent = true;
            this.ChangeInterval = ob.ChangeInterval;
            FontSize = ob.FontSize;
            ShowTextFlag = ob.ShowText;
            if (ob.SelectedImages != null)
            {
                foreach (var savedTextureName in ob.SelectedImages)
                {
                    foreach (var textureDefinition in m_definitions)
                    {
                        if (textureDefinition.Id.SubtypeName == savedTextureName)
                        {
                            m_selectedTexturesToDraw.Add(textureDefinition);
                            break;
                        }
                    }
                }
                m_currentPos = Math.Min(m_currentPos, m_selectedTexturesToDraw.Count);
                RaisePropertiesChanged();
            }

            PowerReceiver = new MyPowerReceiver(
             MyConsumerGroupEnum.Utility,
             false,
             BlockDefinition.RequiredPowerInput,
             () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f);

            PowerReceiver.Update();
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_OxygenTank)objectBuilder;
            m_isStockpiling = builder.IsStockpiling;
            FilledRatio = builder.FilledRatio;

            InitializeConveyorEndpoint();

            NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME;
            m_inventory = new MyInventory(
                BlockDefinition.InventoryMaxVolume,
                BlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this);
            m_inventory.Constraint = BlockDefinition.InputInventoryConstraint;
            m_inventory.Init(builder.Inventory);

            m_inventory.ContentsChanged += m_inventory_ContentsChanged;

            m_autoRefill = builder.AutoRefill;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            UpdateEmissivity();
            UdpateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyOxygenTank_IsWorkingChanged;
        }
Beispiel #22
0
        public void Init(MyObjectBuilder_Battery builder)
        {
            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Charging,
                true,
                MyEnergyConstants.BATTERY_MAX_POWER_INPUT,
                () => (RemainingCapacity < MyEnergyConstants.BATTERY_MAX_CAPACITY) ? MyEnergyConstants.BATTERY_MAX_POWER_INPUT : 0f);
            PowerReceiver.Update();

            if (builder != null)
            {
                (this as IMyPowerProducer).Enabled = builder.ProducerEnabled;
                if (MySession.Static.SurvivalMode)
                    RemainingCapacity = MathHelper.Clamp(builder.CurrentCapacity, 0f, MyEnergyConstants.BATTERY_MAX_CAPACITY);
            }
            RefreshHasRemainingCapacity();
        }
Beispiel #23
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_AirVent)objectBuilder;
            
            m_isDepressurizing = builder.IsDepressurizing;

            InitializeConveyorEndpoint();
            NeedsUpdate = Common.MyEntityUpdateEnum.EACH_10TH_FRAME | Common.MyEntityUpdateEnum.EACH_100TH_FRAME;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            UpdateEmissivity();
            UdpateTexts();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            var programmableBlockBuilder = (MyObjectBuilder_MyProgrammableBlock)objectBuilder;
            m_editorData = m_programData = programmableBlockBuilder.Program;
            m_storageData = programmableBlockBuilder.Storage;
            this.m_terminalRunArgument = programmableBlockBuilder.DefaultRunArgument;

            this.SyncObject = new MySyncProgrammableBlock(this);
            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            PowerReceiver = new MyPowerReceiver(
              MyConsumerGroupEnum.Utility,
              false,
              0.0005f,
              () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f);

            PowerReceiver.Update();
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyProgrammableBlock_IsWorkingChanged;

            if (Sync.IsServer && Sync.Clients != null)
            {
                Sync.Clients.ClientRemoved += ProgrammableBlock_ClientRemoved;
            }
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem = generatorBuilder.UseConveyorSystem;

            NeedsUpdate = Common.MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_inventory = new MyInventory(
                BlockDefinition.InventoryMaxVolume,
                BlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this);
            m_inventory.Constraint = BlockDefinition.InputInventoryConstraint;
            m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist);
            foreach (var id in m_inventory.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_OxygenContainerObject))
                {
                    m_oreConstraint.Add(id);
                }
            }

            m_inventory.Init(generatorBuilder.Inventory);

            m_inventory.ContentsChanged += m_inventory_ContentsChanged;

            m_autoRefill = generatorBuilder.AutoRefill;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Beispiel #26
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                MotorDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0.0f);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            m_dummyDisplacement = 0.0f;
            LoadDummyPosition();

            var ob = objectBuilder as MyObjectBuilder_MotorBase;
            m_rotorBlockId = ob.RotorEntityId;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentMotorBase(this));
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            m_inputInventory = new MyInventory(
                ProductionBlockDefinition.InventoryMaxVolume,
                ProductionBlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this);

            m_outputInventory = new MyInventory(
                ProductionBlockDefinition.InventoryMaxVolume,
                ProductionBlockDefinition.InventorySize,
                MyInventoryFlags.CanSend,
                this);

            var ob = (MyObjectBuilder_ProductionBlock)objectBuilder;
            if (ob.InputInventory != null)
                InputInventory.Init(ob.InputInventory);
            if (ob.OutputInventory != null)
                OutputInventory.Init(ob.OutputInventory);

            m_nextItemId = ob.NextItemId;
            bool nextIdWasZero = m_nextItemId == 0;

            base.IsWorkingChanged += CubeBlock_IsWorkingChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                ProductionBlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(PowerReceiver,this));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            if (ob.Queue != null)
            {
                m_queue.Clear();
                if (m_queue.Capacity < ob.Queue.Length)
                    m_queue.Capacity = ob.Queue.Length;
                for (int i = 0; i < ob.Queue.Length; ++i)
                {
                    var item = ob.Queue[i];
                    Debug.Assert(item.ItemId != null || nextIdWasZero, "Item index was null while next id for production block was given non-zero. This is inconsistency.");

                    var deserializedItem = DeserializeQueueItem(item);
                    Debug.Assert(deserializedItem.Blueprint != null, "Could not add item into production block's queue: Blueprint was not found.");
                    if (deserializedItem.Blueprint != null)
                    {
                        m_queue.Add(deserializedItem);
                        MySandboxGame.Log.WriteLine(string.Format("Could not add item into production block's queue: Blueprint {0} was not found.", item.Id));
                    }
                }

                UpdatePower();
            }

            m_useConveyorSystem = ob.UseConveyorSystem;

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            m_items = new List<ToolbarItem>(2);
            for (int i = 0; i < 2; i++)
            {
                m_items.Add(new ToolbarItem() { EntityID = 0 });
            }
            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            Toolbar.DrawNumbers = false;

            var builder = (MyObjectBuilder_SensorBlock)objectBuilder;
            
            m_fieldMin = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One);
            m_fieldMax = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange));

            PlayProximitySound = builder.PlaySound;
            DetectPlayers = builder.DetectPlayers;
            DetectFloatingObjects = builder.DetectFloatingObjects;
            DetectSmallShips = builder.DetectSmallShips;
            DetectLargeShips = builder.DetectLargeShips;
            DetectStations = builder.DetectStations;
            DetectAsteroids = builder.DetectAsteroids;
            DetectOwner = builder.DetectOwner;
            DetectFriendly = builder.DetectFriendly;
            DetectNeutral = builder.DetectNeutral;
            DetectEnemy = builder.DetectEnemy;
            m_active = builder.IsActive;

            Toolbar.Init(builder.Toolbar, this);

            for (int i = 0; i < 2; i++)
            {
                var item = Toolbar.GetItemAtIndex(i);
                if (item == null)
                    continue;
                m_items.RemoveAt(i);
                m_items.Insert(i, ToolbarItem.FromItem(item));
            }
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.RequiredInputChanged += Receiver_RequiredInputChanged;
            PowerReceiver.Update();

            m_fieldShape = GetHkShape();

            OnClose += delegate(MyEntity self)
            {
                m_fieldShape.RemoveReference();
            };

        }
Beispiel #29
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            if (!MyFakes.ENABLE_PROJECTOR_BLOCK)
            {
                return;
            }

            var projectorBuilder = (MyObjectBuilder_Projector)objectBuilder;
            if (projectorBuilder.ProjectedGrid != null)
            {
                m_projectionOffset = projectorBuilder.ProjectionOffset;
                m_projectionRotation = projectorBuilder.ProjectionRotation;

                m_savedProjection = projectorBuilder.ProjectedGrid;
                m_keepProjection = projectorBuilder.KeepProjection;
            }

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);

            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            IsWorkingChanged += MyProjector_IsWorkingChanged;

            PowerReceiver.Update();
            m_statsDirty = true;
            UpdateText();
            
            SyncObject = new MySyncProjector(this);

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            CubeGrid.OnBlockAdded += previewGrid_OnBlockAdded;
            CubeGrid.OnBlockRemoved += previewGrid_OnBlockRemoved;
        
            CubeGrid.OnGridSplit += CubeGrid_OnGridSplit;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var builder = (MyObjectBuilder_GravityGeneratorSphere)objectBuilder;
            m_radius = builder.Radius;
            m_gravityAcceleration = builder.GravityAcceleration;

            base.Init(objectBuilder, cubeGrid);
            
            SyncObject = new MySyncGravityGeneratorSphere(this);

            m_defaultVolume = (float)(Math.Pow(DEFAULT_RADIUS, BlockDefinition.ConsumptionPower) * Math.PI * 0.75);
            
                PowerReceiver = new MyPowerReceiver(
                    MyConsumerGroupEnum.Utility,
                    false,
                    CalculateRequiredPowerInputForRadius(BlockDefinition.MaxRadius),
                    this.CalculateRequiredPowerInput);
                if (CubeGrid.CreatePhysics)
                {
                    PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
                    PowerReceiver.RequiredInputChanged += Receiver_RequiredInputChanged;
                    PowerReceiver.Update();
                    AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(PowerReceiver, this));
                    AddDebugRenderComponent(new Components.MyDebugRenderComponentGravityGeneratorSphere(this));
                }
        }
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            base.Init(builder, cubeGrid);

            var ob = (MyObjectBuilder_AirtightDoorGeneric)builder;
            m_open = ob.Open;
            m_currOpening = ob.CurrOpening;

            m_openingSpeed = BlockDefinition.OpeningSpeed;
            m_sound = new MySoundPair(BlockDefinition.Sound);
            m_subpartMovementDistance = BlockDefinition.SubpartMovementDistance;

            PowerReceiver = new MyPowerReceiver(MyConsumerGroupEnum.Doors,
                false,
                BlockDefinition.PowerConsumptionMoving,
                () => UpdatePowerInput());
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            if (!Enabled || !PowerReceiver.IsPowered)
                UpdateDoorPosition();

            OnStateChange();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            PowerReceiver.Update();
        }
        private void Receiver_RequiredInputChanged(MyPowerReceiver changedConsumer, float oldRequirement, float newRequirement)
        {
            if (m_needsRecompute)
                RecomputePowerDistribution();

            // Go over all priorities, starting from the changedConsumer.
            int idx = (int)changedConsumer.Group;
            MyDebug.AssertDebug(m_consumerDataByPriority[idx].RequiredInput >= 0.0f);
            m_consumerDataByPriority[idx].RequiredInput = 0.0f;
            foreach (var consumer in m_consumersByPriority[idx])
                m_consumerDataByPriority[idx].RequiredInput += consumer.PowerReceiver.RequiredInput;

            // Update cumulative requirements.
            float cumulative = (idx != 0) ? m_consumerDataByPriority[idx - 1].RequiredInputCumulative
                                          : 0.0f;
            for (int i = idx; i < m_consumerDataByPriority.Length; ++i)
            {
                cumulative += m_consumerDataByPriority[i].RequiredInput;
                m_consumerDataByPriority[i].RequiredInputCumulative = cumulative;
            }

            RecomputePowerDistributionPartial(idx, m_consumerDataByPriority[idx].AvailablePower);
            MyDebug.AssertDebug(m_consumerDataByPriority[idx].RequiredInput >= 0.0f);
        }