Example #1
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (IsFunctional)
            {
                if (SemiautoEnabled)
                {
                    if (CurrentStoredPower == 0)
                    {
                        SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, false);
                        SyncObject.SendProducerEnableChange(false);
                        SyncObject.SendSemiautoEnableChange(SemiautoEnabled);
                    }
                    if (CurrentStoredPower == MaxStoredPower)
                    {
                        SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, true);
                        SyncObject.SendProducerEnableChange(true);
                        SyncObject.SendSemiautoEnableChange(SemiautoEnabled);
                    }
                }

                ResourceSink.Update();
                UpdateMaxOutputAndEmissivity();

                int timeDelta = 100 * MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS;
                if (!MySession.Static.CreativeMode)
                {
                    if ((Sync.IsServer && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (!SourceComp.ProductionEnabled)
                        {
                            StorePower(timeDelta, ResourceSink.CurrentInput);
                        }
                        else
                        {
                            ConsumePower(timeDelta);
                        }
                    }
                }
                else
                {
                    if ((Sync.IsServer && IsFunctional && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (!SourceComp.ProductionEnabled)
                        {
                            StorePower(timeDelta, (SourceComp.ProductionToCapacityMultiplier * MaxStoredPower) / 8f);
                        }
                        else
                        {
                            UpdateIsWorking();
                            if (!SourceComp.HasCapacityRemaining)
                            {
                                return;
                            }
                            ResourceSink.Update();
                            CalculateOutputTimeRemaining();
                        }
                    }
                }

                if (!SourceComp.ProductionEnabled)
                {
                    CalculateInputTimeRemaining();
                }
                else
                {
                    CalculateOutputTimeRemaining();
                }
            }
        }
Example #2
0
 protected override void OnEnabledChanged()
 {
     ResourceSink.Update();
     base.OnEnabledChanged();
 }
Example #3
0
        public override void UpdateBeforeSimulation()
        {
            if (FullyClosed)
            {
                m_time = 0f;
            }
            else if (FullyOpen)
            {
                if (m_totalTime != m_time)
                {
                    m_totalTime = m_time;
                }

                m_time = m_totalTime;
            }

            for (int i = 0; i < m_openingSequence.Count; i++)
            {
                float maxOpen = m_openingSequence[i].MaxOpen;

                if ((Open && (m_currentOpening[i] == maxOpen)) || (!Open && (m_currentOpening[i] == 0f)))
                {
                    if (m_emitter[i] != null && m_emitter[i].IsPlaying && m_emitter[i].Loop)
                    {
                        m_emitter[i].StopSound(false);
                    }

                    m_currentSpeed[i] = 0f;
                }

                if (Enabled && ResourceSink != null && ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId) && m_currentSpeed[i] != 0)
                {
                    string soundName = "";
                    if (Open)
                    {
                        soundName = m_openingSequence[i].OpenSound;
                    }
                    else
                    {
                        soundName = m_openingSequence[i].CloseSound;
                    }

                    if (!String.IsNullOrEmpty(soundName))
                    {
                        StartSound(i, new MySoundPair(soundName));
                    }
                }
                else
                {
                    if (m_emitter[i] != null)
                    {
                        m_emitter[i].StopSound(false);
                    }
                }
            }

            if (m_stateChange && ((m_open && FullyOpen) || (!m_open && FullyClosed)))
            {
                ResourceSink.Update();
                RaisePropertiesChanged();
                if (!m_open)
                {
                    var handle = DoorStateChanged;
                    if (handle != null)
                    {
                        handle(m_open);
                    }
                }
                m_stateChange = false;
            }

            base.UpdateBeforeSimulation();
            UpdateCurrentOpening();

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            // Draw Physical primitives for Subparts
            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_PHYSICS)
            {
                for (int i = 0; i < m_subparts.Count; i++)
                {
                    m_subparts[i].DebugDraw();
                    m_subparts[i].DebugDrawPhysics();
                }
            }
        }
Example #4
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");
        }
Example #5
0
 public void EndShoot(MyShootActionEnum action)
 {
     WantsToDrill = false;
     ResourceSink.Update();
 }
Example #6
0
        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

            if (!Sync.IsServer || !IsWorking || !ResourceSink.IsPowered)
            {
                return;
            }

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax.Value + m_fieldMin.Value) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
                ResourceSink.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin.Value, m_fieldMax.Value).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());

            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations);

            m_potentialVoxelPenetrations.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);//disabled until heightmap queries are finished

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            bool empty = true;

            foreach (var entity in m_potentialPenetrations)
            {
                if (entity is MyVoxelBase)
                {
                    //voxels are handled in different loop (becaose of planets)
                    continue;
                }
                if (ShouldDetect(entity))
                {
                    Quaternion rotation2;
                    Vector3    posDiff;
                    HkShape?   shape2;
                    if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                    {
                        if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                        {
                            LastDetectedEntity = entity;
                            empty = false;
                            break;
                        }
                    }
                }
            }

            if (DetectAsteroids)
            {
                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    var voxel = entity as MyVoxelPhysics;
                    if (voxel != null)
                    {
                        Vector3D localPositionMin, localPositionMax;

                        VRage.Voxels.MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Min, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMin);
                        VRage.Voxels.MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Max, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMax);
                        var aabb = new BoundingBox(localPositionMin, localPositionMax);
                        aabb.Translate(voxel.StorageMin);
                        if (voxel.Storage.Intersect(ref aabb) != ContainmentType.Disjoint)
                        {
                            LastDetectedEntity = voxel;
                            empty = false;
                            break;
                        }
                    }
                    else
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }
            }
            IsActive = !empty;
            m_potentialPenetrations.Clear();
            m_potentialVoxelPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Example #7
0
 public override void OnAddedToScene(object source)
 {
     base.OnAddedToScene(source);
     UpdateEmissivity();
     ResourceSink.Update();
 }
Example #8
0
 private void UpdateMaxOutputAndEmissivity()
 {
     ResourceSink.Update();
     SourceComp.SetMaxOutputByType(MyResourceDistributorComponent.ElectricityId, (ComputeMaxPowerOutput()));
     UpdateEmissivity();
 }
Example #9
0
 void OnBroadcastRadiusChanged()
 {
     ResourceSink.Update();
     UpdateText();
 }
Example #10
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (IsFunctional)
            {
                if (SemiautoEnabled)
                {
                    if (CurrentStoredPower == 0)
                    {
                        OnlyRecharge  = true;
                        OnlyDischarge = false;
                    }
                    else if (CurrentStoredPower == MaxStoredPower)
                    {
                        OnlyRecharge  = false;
                        OnlyDischarge = true;
                    }
                }

                UpdateMaxOutputAndEmissivity();

                float timeDeltaMs = (MySession.Static.GameplayFrameCounter - m_lastUpdateTime) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 1000f;
                m_lastUpdateTime = MySession.Static.GameplayFrameCounter;
                if (!MySession.Static.CreativeMode)
                {
                    if ((Sync.IsServer && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (OnlyRecharge)
                        {
                            StorePower(timeDeltaMs, ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId));
                        }
                        else if (OnlyDischarge)
                        {
                            ConsumePower(timeDeltaMs, SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId));
                        }
                        else
                        {
                            TransferPower(timeDeltaMs, ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId), SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId));
                        }
                    }
                }
                else
                {
                    if ((Sync.IsServer && IsFunctional && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (OnlyRecharge || !OnlyDischarge)
                        {
                            float powerToStore = (SourceComp.ProductionToCapacityMultiplierByType(MyResourceDistributorComponent.ElectricityId) * MaxStoredPower) / 8f;
                            powerToStore *= Enabled && IsFunctional ? 1f : 0f;
                            StorePower(timeDeltaMs, powerToStore);
                        }
                        else
                        {
                            UpdateIsWorking();
                            if (!SourceComp.HasCapacityRemainingByType(MyResourceDistributorComponent.ElectricityId))
                            {
                                return;
                            }
                            CalculateOutputTimeRemaining();
                        }
                    }
                }
                ResourceSink.Update();

                if (OnlyRecharge)
                {
                    CalculateInputTimeRemaining();
                }
                else if (OnlyDischarge)
                {
                    CalculateOutputTimeRemaining();
                }
                else
                {
                    if (ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId) > SourceComp.CurrentOutputByType(MyResourceDistributorComponent.ElectricityId))
                    {
                        CalculateInputTimeRemaining();
                    }
                    else
                    {
                        CalculateOutputTimeRemaining();
                    }
                }
            }
        }
Example #11
0
 protected override void OnEnabledChanged()
 {
     UpdateMaxOutputAndEmissivity();
     ResourceSink.Update();
     base.OnEnabledChanged();
 }
Example #12
0
 void MyBatteryBlock_IsWorkingChanged(MyCubeBlock obj)
 {
     UpdateMaxOutputAndEmissivity();
     ResourceSink.Update();
 }
Example #13
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var sourceDataList = new List <MyResourceSourceInfo>
            {
                new MyResourceSourceInfo {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = BlockDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60
                }
            };

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

            var batteryBuilder = (MyObjectBuilder_BatteryBlock)objectBuilder;

            SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, batteryBuilder.ProducerEnabled);

            MaxStoredPower = BlockDefinition.MaxStoredPower;

            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                Sink_ComputeRequiredPower);

            base.Init(objectBuilder, cubeGrid);

            ResourceSink.Update();

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

            if (batteryBuilder.CurrentStoredPower >= 0)
            {
                CurrentStoredPower = batteryBuilder.CurrentStoredPower;
            }
            else
            {
                CurrentStoredPower = BlockDefinition.InitialStoredPowerRatio * BlockDefinition.MaxStoredPower;
            }

            m_storedPower.Value = CurrentStoredPower;


            SemiautoEnabled = batteryBuilder.SemiautoEnabled;
            OnlyRecharge    = !batteryBuilder.ProducerEnabled;
            OnlyDischarge   = batteryBuilder.OnlyDischargeEnabled;
            UpdateMaxOutputAndEmissivity();

            UpdateText();

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

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_lastUpdateTime = MySession.Static.GameplayFrameCounter;

            if (IsWorking)
            {
                OnStartWorking();
            }
        }
Example #14
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_wantsToCollect = false;
            AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase));

			var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                def.ResourceSinkGroup,
                ComputeMaxRequiredPower(),
                ComputeRequiredPower);
	        ResourceSink = sinkComp;
			ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
			ResourceSink.Update();

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

            var obDrill = (MyObjectBuilder_Drill)builder;
            m_inventory.Init(obDrill.Inventory);

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

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_useConveyorSystem = obDrill.UseConveyorSystem;

            UpdateDetailedInfo();

            m_wantsToDrill = obDrill.Enabled;
            IsWorkingChanged += OnIsWorkingChanged;
        }
Example #15
0
 void IsPoweredChanged()
 {
     ResourceSink.Update();
     UpdateText();
     UpdateEmissivity();
 }
Example #16
0
        protected override void UpdateProduction(int timeDelta)
        {
            if (!Enabled)
            {
                CurrentState = StateEnum.Disabled;
                return;
            }

            if (!ResourceSink.IsPowered || ResourceSink.CurrentInput < GetOperationalPowerConsumption())
            {
                if (!ResourceSink.IsPowerAvailable(MyResourceDistributorComponent.ElectricityId, GetOperationalPowerConsumption()))
                {
                    CurrentState = StateEnum.NotEnoughPower;
                    return;
                }
            }

            if (!IsWorking)
            {
                CurrentState = StateEnum.NotWorking;
                return;
            }

            if (IsQueueEmpty)
            {
                return;
            }

            var firstQueueItem = TryGetFirstQueueItem();

            while (timeDelta > 0)
            {
                if (!firstQueueItem.HasValue)
                {
                    CurrentProgress = 0f;
                    if (IsQueueEmpty)
                    {
                        IsProducing = false;
                        return;
                    }

                    if (!Sync.IsServer)
                    {
                        break;
                    }

                    firstQueueItem = TryGetFirstQueueItem();
                }

                var currentBlueprint = firstQueueItem.Value.Blueprint;
                CurrentState = CheckInventory(currentBlueprint);
                if (CurrentState != StateEnum.Ok)
                {
                    IsProducing = false;
                    return;
                }
                var remainingTime = calculateBlueprintProductionTime(currentBlueprint) - CurrentProgress * calculateBlueprintProductionTime(currentBlueprint);

                if (timeDelta >= remainingTime)
                {
                    if (Sync.IsServer)
                    {
                        if (DisassembleEnabled)
                        {
                            FinishDisassembling(currentBlueprint);
                        }
                        else
                        {
                            if (RepeatEnabled)
                            {
                                InsertQueueItemRequest(-1, currentBlueprint);
                            }
                            FinishAssembling(currentBlueprint);
                        }

                        RemoveFirstQueueItemAnnounce(1);
                    }
                    timeDelta      -= (int)Math.Ceiling(remainingTime);
                    CurrentProgress = 0;
                    firstQueueItem  = null;
                }
                else
                {
                    CurrentProgress += timeDelta / calculateBlueprintProductionTime(currentBlueprint);
                    timeDelta        = 0;
                }
            }
            IsProducing = IsWorking && !IsQueueEmpty;
        }
Example #17
0
 void ComponentStack_IsFunctionalChanged()
 {
     ResourceSink.Update();
     UpdateText();
     UpdateEmissivity();
 }
Example #18
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_OxygenTank)objectBuilder;

            IsStockpiling = builder.IsStockpiling;

            InitializeConveyorEndpoint();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();

                if (this.GetInventory() != null)
                {
                    this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint;
                }
            }

            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive);
                inventory.Constraint = BlockDefinition.InputInventoryConstraint;
                Components.Add <MyInventoryBase>(inventory);
                inventory.Init(builder.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            m_autoRefill = builder.AutoRefill;

            var sourceDataList = new List <MyResourceSourceInfo>
            {
                new MyResourceSourceInfo {
                    ResourceTypeId = BlockDefinition.StoredGasId, DefinedOutput = 0.05f * BlockDefinition.Capacity
                },
            };

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList);
            SourceComp.OutputChanged += Source_OutputChanged;

            SourceComp.Enabled = Enabled;

            var sinkDataList = new List <MyResourceSinkInfo>
            {
                new MyResourceSinkInfo {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower
                },
                new MyResourceSinkInfo {
                    ResourceTypeId = BlockDefinition.StoredGasId, MaxRequiredInput = Capacity, RequiredInputFunc = ComputeRequiredGas
                },
            };

            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                sinkDataList);
            ResourceSink.IsPoweredChanged    += PowerReceiver_IsPoweredChanged;
            ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged;

            m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter;
            m_lastInputUpdateTime  = MySession.Static.GameplayFrameCounter;
            m_nextGasTransfer      = 0f;

            ChangeFilledRatio(builder.FilledRatio);
            ResourceSink.Update();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

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

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
            ResourceSink = sinkComp;

            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.Value = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One);
            m_fieldMax.Value = 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.Value        = 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;


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

            m_fieldShape = GetHkShape();

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

            m_gizmoColor = MySandboxGame.IsDirectX11 ? new Vector4(0.35f, 0, 0, 0.5f) : new Vector4(0.1f, 0, 0, 0.1f);
        }
Example #20
0
        private float ComputeRequiredPower()
        {
            if (!MySession.Static.Settings.EnableOxygen && BlockDefinition.StoredGasId == m_oxygenGasId || !Enabled || !IsFunctional)
            {
                return(0f);
            }

            return((SourceComp.CurrentOutputByType(BlockDefinition.StoredGasId) > 0 || ResourceSink.CurrentInputByType(BlockDefinition.StoredGasId) > 0)
                    ? BlockDefinition.OperationalPowerConsumption : BlockDefinition.StandbyPowerConsumption);
        }
Example #21
0
 public override void OnBuildSuccess(long builtBy)
 {
     ResourceSink.Update();
     base.OnBuildSuccess(builtBy);
 }
Example #22
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            ResourceSink.Update();
        }
Example #23
0
 void OnIsWorkingChanged(MyCubeBlock obj)
 {
     ResourceSink.Update();
 }
Example #24
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (IsFunctional)
            {
                if (!IsFull && m_isRecharging)
                {
                    StorePower(100f * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS, ResourceSink.CurrentInputByType(MyResourceDistributorComponent.ElectricityId));
                }
            }

            UpdateEmissivity();
            UpdateText();
        }
Example #25
0
 void ComponentStack_IsFunctionalChanged()
 {
     ResourceSink.Update();
 }
Example #26
0
 void ComponentStack_IsFunctionalChanged()
 {
     SourceComp.Enabled = IsWorking;
     ResourceSink.Update();
     UpdateEmissivity();
 }
Example #27
0
 public override void OnBuildSuccess(long builtBy)
 {
     ResourceSink.Update();
     UpdateHavokCollisionSystemID(CubeGrid.GetPhysicsBody().HavokCollisionSystemID);
     base.OnBuildSuccess(builtBy);
 }
Example #28
0
 void MyAirVent_IsWorkingChanged(MyCubeBlock obj)
 {
     SourceComp.Enabled = IsWorking;
     ResourceSink.Update();
     UpdateEmissivity();
 }
Example #29
0
 protected override bool CheckIsWorking()
 {
     return(ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId) && base.CheckIsWorking());
 }
Example #30
0
 void UpdateReceiver()
 {
     ResourceSink.Update();
 }