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

            if (m_producedSinceLastUpdate)
            {
                if (m_effect == null)
                {
                    CreateEffect();
                }
            }
            else
            {
                if (m_effect != null)
                {
                    m_effect.Stop();
                    m_effect = null;
                }
            }

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSound();
            }

            m_isProducing             = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            var block = GetOxygenBlock();

            int sourceUpdateFrames = (m_updateCounter - m_lastOutputUpdateTime);
            int sinkUpdateFrames   = (m_updateCounter - m_lastInputUpdateTime);

            float gasInput      = GasInputPerUpdate * sinkUpdateFrames;
            float gasOutput     = GasOutputPerUpdate * sourceUpdateFrames;
            float totalTransfer = gasInput - gasOutput + m_nextGasTransfer;

            Transfer(totalTransfer);

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)(block.Room != null ? block.Room.OxygenAmount : 0));

            m_updateCounter        = 0;
            m_lastOutputUpdateTime = m_updateCounter;
            m_lastInputUpdateTime  = m_updateCounter;
            ResourceSink.Update();

            UdpateTexts();
        }
Example #2
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();
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0.0f);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

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

            var ob = objectBuilder as MyObjectBuilder_PistonBase;

            Velocity.Value = ob.Velocity * BlockDefinition.MaxVelocity;
            MaxLimit.Value = ob.MaxLimit.HasValue ? Math.Min(DenormalizeDistance(ob.MaxLimit.Value), BlockDefinition.Maximum) : BlockDefinition.Maximum;
            MinLimit.Value = ob.MinLimit.HasValue ? Math.Max(DenormalizeDistance(ob.MinLimit.Value), BlockDefinition.Minimum) : BlockDefinition.Minimum;

            if (ob.TopBlockId.HasValue && ob.TopBlockId.Value != 0)
            {
                MyDeltaTransform?deltaTransform = ob.MasterToSlaveTransform.HasValue ? ob.MasterToSlaveTransform.Value : (MyDeltaTransform?)null;
                m_connectionState.Value = new State()
                {
                    TopBlockId = ob.TopBlockId, MasterToSlave = deltaTransform, Welded = ob.IsWelded || ob.ForceWeld
                };
            }

            m_currentPos.Value = ob.CurrentPosition;

            CubeGrid.OnPhysicsChanged += cubeGrid_OnPhysicsChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            float defaultWeldSpeed = ob.WeldSpeed; //weld before reaching the max speed

            defaultWeldSpeed   *= defaultWeldSpeed;
            m_weldSpeedSq.Value = defaultWeldSpeed;
            m_forceWeld.Value   = ob.ForceWeld;
        }
Example #4
0
 private void ComponentStack_IsFunctionalChanged()
 {
     ResourceSink.Update();
     if (IsFunctional)
     {
         if (ShowTextOnScreen == false)
         {
             Render.ChangeTexture(GetPathForID(DEFAULT_ONLINE_TEXTURE));
         }
         m_previousTextureID = null;
         m_forceUpdateText   = ShowTextOnScreen;
     }
     else
     {
         Render.ChangeTexture(GetPathForID(DEFAULT_OFFLINE_TEXTURE));
     }
 }
Example #5
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (Sync.IsServer && IsWorking)
            {
                UpdateActions();
            }

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSound();
            }

            if (m_producedSinceLastUpdate == false)
            {
                if (m_effect != null)
                {
                    m_effect.Stop();
                    m_effect = null;
                }
            }

            m_isProducing             = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            var block = GetOxygenBlock();

            int sourceUpdateFrames = (MySession.Static.GameplayFrameCounter - m_lastOutputUpdateTime);
            int sinkUpdateFrames   = (MySession.Static.GameplayFrameCounter - m_lastInputUpdateTime);

            m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter;
            m_lastInputUpdateTime  = MySession.Static.GameplayFrameCounter;

            float gasInput      = GasInputPerUpdate * sinkUpdateFrames;
            float gasOutput     = GasOutputPerUpdate * sourceUpdateFrames;
            float totalTransfer = gasInput - gasOutput + m_nextGasTransfer;

            Transfer(totalTransfer);

            SourceComp.SetRemainingCapacityByType(m_oxygenGasId, (float)(block.Room != null && block.Room.IsPressurized ? block.Room.OxygenAmount : (MyOxygenProviderSystem.GetOxygenInPoint(WorldMatrix.Translation) != 0 ? BlockDefinition.VentilationCapacityPerSecond * 100 : 0f)));

            ResourceSink.Update();

            UdpateTexts();
            UpdateEmissivity();
        }
Example #6
0
        public override void UpdateBeforeSimulation()
        {
            if (!m_updated)
            {
                MatrixD tmp = PositionComp.WorldMatrix;
                foreach (var subpart in m_subparts)
                {
                    subpart.PositionComp.UpdateWorldMatrix(ref tmp);
                }
                m_updated = true;
            }
            if (m_stateChange && ((m_open && 1f - m_currOpening < EPSILON) || (!m_open && m_currOpening < EPSILON)))
            {
                //END OF MOVEMENT
                if (m_soundEmitter != null && m_soundEmitter.Loop)
                {
                    m_soundEmitter.StopSound(false);
                }
                m_currSpeed  = 0;
                NeedsUpdate &= ~(MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME);
                ResourceSink.Update();
                RaisePropertiesChanged();
                if (!m_open)
                {   //finished closing - they are airtight now
                    var handle = DoorStateChanged;
                    if (handle != null)
                    {
                        handle(m_open);
                    }
                }
                m_stateChange = false;
            }
            if (m_soundEmitter != null)
            {
                if (Enabled && ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId) && m_currSpeed != 0)
                {
                    StartSound(m_sound);
                }
            }

            base.UpdateBeforeSimulation();
            UpdateCurrentOpening();

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }
Example #7
0
        protected override void InitializeSinkComponent()
        {
            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                CalculateRequiredPowerInputForRadius(BlockDefinition.MaxRadius),
                CalculateRequiredPowerInput);
            ResourceSink = sinkComp;

            if (CubeGrid.CreatePhysics)
            {
                ResourceSink.IsPoweredChanged     += Receiver_IsPoweredChanged;
                ResourceSink.RequiredInputChanged += Receiver_RequiredInputChanged;
                ResourceSink.Update();
                AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));
            }
        }
Example #8
0
        public void Shoot(MyShootActionEnum action, Vector3 direction, Vector3D?overrideWeaponPos, string gunAction)
        {
            if (action != MyShootActionEnum.PrimaryAction)
            {
                return;
            }

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;

            if (m_shootHeatup < HeatUpFrames)
            {
                m_shootHeatup++;
                return;
            }

            WantsToActivate = true;
            ResourceSink.Update();
        }
Example #9
0
        internal void ChangeFilledRatio(float newFilledRatio, bool updateSync = false)
        {
            m_nextGasTransfer = 0f;
            float oldFilledRatio = FilledRatio;

            if (oldFilledRatio != newFilledRatio)
            {
                if (updateSync)
                {
                    SyncObject.ChangeFillRatioAmount(newFilledRatio);
                }
                FilledRatio = newFilledRatio;
                SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, FilledRatio * Capacity);
                ResourceSink.Update();
                UpdateEmissivity();
                UdpateText();
            }
        }
Example #10
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var ob = objectBuilder as MyObjectBuilder_Collector;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute(BlockDefinition.ResourceSinkGroup),
                BlockDefinition.RequiredPowerInput,
                ComputeRequiredPower);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            m_useConveyorSystem.Value = true;
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

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

            if (Sync.IsServer && CubeGrid.CreatePhysics)
            {
                LoadDummies();
            }

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

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

            m_useConveyorSystem.Value = ob.UseConveyorSystem;

            ResourceSink.Update();
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (ResourceSink != null)
            {
                ResourceSink.Update();
            }

            if (IsWorking)
            {
                foreach (IMyEntity entityInterface in m_containedEntities)
                {
                    MyEntity       entity    = entityInterface as MyEntity;
                    MyCharacter    character = entity as MyCharacter;
                    IMyVirtualMass mass      = entity as IMyVirtualMass;

                    var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(entity.WorldMatrix.Translation);
                    var gravity = GetWorldGravity(entity.WorldMatrix.Translation) * MyGravityProviderSystem.CalculateArtificialGravityStrengthMultiplier(naturalGravityMultiplier);

                    if (mass != null && entity.Physics.RigidBody.IsActive)
                    {
                        if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_MISCELLANEOUS)
                        {
                            MyRenderProxy.DebugDrawSphere(entity.WorldMatrix.Translation, 0.2f, mass.IsWorking ? Color.Blue : Color.Red, 1.0f, false);
                        }
                        if (mass.IsWorking && entity.Physics.RigidBody.IsActive)
                        {
                            ((IMyEntity)mass.CubeGrid).Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * mass.VirtualMass, entity.WorldMatrix.Translation, null);
                        }
                    }
                    else if (!entity.Physics.IsKinematic &&
                             !entity.Physics.IsStatic &&
                             entity.Physics.RigidBody2 == null && //jn: TODO this is actualy check for large grid
                             character == null)
                    {
                        if (entity.Physics.RigidBody != null && entity.Physics.RigidBody.IsActive)
                        {
                            entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * entity.Physics.RigidBody.Mass, null, null);
                        }
                    }
                }
            }
        }
Example #12
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var timerBlockDefinition = BlockDefinition as MyTimerBlockDefinition;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                timerBlockDefinition.ResourceSinkGroup,
                0.0000001f,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0f);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_TimerBlock;

            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 9, 10);
            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            if (ob.JustTriggered)
            {
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }

            IsCountingDown       = ob.IsCountingDown;
            m_countdownMsStart   = ob.Delay;
            m_countdownMsCurrent = ob.CurrentTime;

            if (m_countdownMsCurrent > 0)
            {
                NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            }


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

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

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

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MotorDefinition.ResourceSinkGroup,
                MotorDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? sinkComp.MaxRequiredInput : 0.0f);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            ResourceSink.Update();

            m_dummyDisplacement.Value = 0.0f;
            LoadDummyPosition();

            var ob = objectBuilder as MyObjectBuilder_MotorBase;

            if (ob.RotorEntityId.HasValue && ob.RotorEntityId.Value != 0)
            {
                MyDeltaTransform?deltaTransform = ob.MasterToSlaveTransform.HasValue ? ob.MasterToSlaveTransform.Value : (MyDeltaTransform?)null;
                m_rotorBlockId.Value = new State()
                {
                    OtherEntityId = ob.RotorEntityId, MasterToSlave = deltaTransform
                };
            }

            m_weldedEntityId.Value = ob.WeldedEntityId;

            AddDebugRenderComponent(new Components.MyDebugRenderComponentMotorBase(this));
            cubeGrid.OnPhysicsChanged += cubeGrid_OnPhysicsChanged;

            float defaultWeldSpeed = ob.weldSpeed; //weld before reaching the max speed

            defaultWeldSpeed   *= defaultWeldSpeed;
            m_weldSpeedSq.Value = defaultWeldSpeed;
            m_forceWeld.Value   = ob.forceWeld;
        }
Example #14
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var def      = BlockDefinition as MyPoweredCargoContainerDefinition;
            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute(def.ResourceSinkGroup),
                MyEnergyConstants.MAX_REQUIRED_POWER_COLLECTOR,
                () => base.CheckIsWorking() ? ResourceSink.MaxRequiredInput : 0f);
            ResourceSink = sinkComp;
            ResourceSink.Update();

            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_Collector;

            m_useConveyorSystem.Value = true;
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

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

            if (Sync.IsServer && CubeGrid.CreatePhysics)
            {
                LoadDummies();
            }


            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

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

            m_useConveyorSystem.Value = ob.UseConveyorSystem;
        }
Example #15
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            ResourceSink.Update();

            int updatesSinceSourceUpdate = (MySession.Static.GameplayFrameCounter - m_lastSourceUpdate);

            foreach (var gasId in SourceComp.ResourceTypes)
            {
                var   tmpGasId  = gasId;
                float gasOutput = GasOutputPerUpdate(ref tmpGasId) * updatesSinceSourceUpdate;
                ProduceGas(ref tmpGasId, gasOutput);
            }

            if (Sync.IsServer && IsWorking)
            {
                if (m_useConveyorSystem && this.GetInventory().VolumeFillFactor < 0.6f)
                {
                    MyGridConveyorSystem.PullAllRequest(this, this.GetInventory(), OwnerId, HasIce() ? this.GetInventory().Constraint : m_oreConstraint);
                }

                if (AutoRefill && CanRefill())
                {
                    RefillBottles();
                }
            }

            UpdateEmissivity();

            if (MyFakes.ENABLE_OXYGEN_SOUNDS)
            {
                UpdateSounds();
            }

            m_isProducing             = m_producedSinceLastUpdate;
            m_producedSinceLastUpdate = false;
            foreach (var gasId in SourceComp.ResourceTypes)
            {
                m_producedSinceLastUpdate = m_producedSinceLastUpdate || (SourceComp.CurrentOutputByType(gasId) > 0);
            }

            m_lastSourceUpdate = MySession.Static.GameplayFrameCounter;
        }
Example #16
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            IsWorkingChanged += OnIsWorkingChanged;
            NeedsUpdate      |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            InitializeConveyorEndpoint();

            SourceComp.Init(
                BlockDefinition.ResourceSourceGroup,
                new MyResourceSourceInfo
            {
                ResourceTypeId = BlockDefinition.ProducedGas,
                DefinedOutput  = BlockDefinition.MaxGasOutput,
                ProductionToCapacityMultiplier = 1,
                IsInfiniteCapacity             = true,
            });
            SourceComp.Enabled = IsWorking;

            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                new MyResourceSinkInfo
            {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = ComputeRequiredPower,
            });
            ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink.Update();

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

            SolarComponent.Initialize(BlockDefinition.PanelOrientation, BlockDefinition.IsTwoSided, BlockDefinition.PanelOffset, this);

            AddDebugRenderComponent(new MyDebugRenderComponentSolarPanel(this));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_OnIsFunctionalChanged;

            UpdateVisual();
            UpdateDisplay();
        }
Example #17
0
 void WantstoDrillChanged()
 {
     ResourceSink.Update();
     if ((Enabled || WantsToDrill) && IsFunctional && ResourceSink != null && ResourceSink.IsPowered)
     {
         // starts the animation
         if (!m_drillBase.IsDrilling)
         {
             m_drillBase.Drill(false, false);
         }
         NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;
     }
     else
     {
         NeedsUpdate &= ~MyEntityUpdateEnum.EACH_10TH_FRAME;
         SetupDrillFrameCountdown();
         m_drillBase.StopDrill();
     }
 }
Example #18
0
        protected override void ComponentStack_IsFunctionalChanged()
        {
            base.ComponentStack_IsFunctionalChanged();

            if (IsFunctional)
            {
                Debug.Assert(m_pilot == null, "A pilot was found in a newly working cockpit. He shouldn't have been there.");
            }
            else
            {
                if (m_pilot != null)
                {
                    RemovePilot();
                }

                ChangeGasFillLevel(0);
                ResourceSink.Update();
            }
        }
Example #19
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();
            if (CubeGrid.Physics == null)
            {
                return;
            }

            float maxGasOutputFactor = SourceComp.ProductionEnabledByType(BlockDefinition.ProducedGas) ? SolarComponent.MaxOutput : 0f;

            if (maxGasOutputFactor != m_maxGasOutputFactor)
            {
                m_maxGasOutputFactor = maxGasOutputFactor;
                SourceComp.SetMaxOutputByType(BlockDefinition.ProducedGas, SourceComp.DefinedOutputByType(BlockDefinition.ProducedGas) * m_maxGasOutputFactor);
                UpdateVisual();
                UpdateDisplay();
            }

            ResourceSink.Update();
        }
Example #20
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            ResourceSink.Update();
            if (m_removeRequested)
            {
                m_frameCount++;
                if (m_frameCount > 10)
                {
                    UpdateIsWorking();
                    if (!IsWorking && IsProjecting())
                    {
                        RemoveProjection(true);
                    }
                    m_frameCount      = 0;
                    m_removeRequested = false;
                }
            }
        }
Example #21
0
        protected virtual void StopShooting()
        {
            m_wantsToActivate        = false;
            m_isActivated            = false;
            m_isActivatedOnSomething = false;

            if (Physics != null)
            {
                Physics.Enabled = false;
            }
            if (ResourceSink != null)
            {
                ResourceSink.Update();
            }

            m_shootHeatup = 0;

            StopEffects();
            StopLoopSound();
        }
Example #22
0
        void OnBlueprintScreen_Closed(MyGuiScreenBase source)
        {
            ResourceSink.Update();
            UpdateIsWorking();
            if (m_clipboard.CopiedGrids.Count == 0 || !IsWorking)
            {
                RemoveProjection(false);
                return;
            }
            if (m_clipboard.GridSize != CubeGrid.GridSize)
            {
                RemoveProjection(false);
                ShowNotification(MySpaceTexts.NotificationProjectorGridSize);
                return;
            }
            if (m_clipboard.CopiedGrids.Count > 1)
            {
                ShowNotification(MySpaceTexts.NotificationProjectorMultipleGrids);
            }

            int largestGridIndex      = -1;
            int largestGridBlockCount = -1;

            for (int i = 0; i < m_clipboard.CopiedGrids.Count; i++)
            {
                int currentGridBlockCount = m_clipboard.CopiedGrids[i].CubeBlocks.Count;
                if (currentGridBlockCount > largestGridBlockCount)
                {
                    largestGridBlockCount = currentGridBlockCount;
                    largestGridIndex      = i;
                }
            }

            m_originalGridBuilder = (MyObjectBuilder_CubeGrid)m_clipboard.CopiedGrids[largestGridIndex].Clone();

            m_clipboard.ProcessCubeGrid(m_clipboard.CopiedGrids[largestGridIndex]);

            MyEntities.RemapObjectBuilder(m_originalGridBuilder);
            SendNewBlueprint(m_originalGridBuilder);
        }
Example #23
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var soundBlockDefinition = BlockDefinition as MySoundBlockDefinition;

            Debug.Assert(soundBlockDefinition != null);

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                soundBlockDefinition.ResourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_SOUNDBLOCK,
                UpdateRequiredPowerInput);
            sinkComp.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_SoundBlock)objectBuilder;

            Volume     = builder.Volume;
            Range      = builder.Range;
            LoopPeriod = builder.LoopPeriod;
            if (builder.IsPlaying)
            {
                m_willStartSound = true;
            }
            InitCue(builder.CueName);

            ResourceSink.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            for (int i = 0; i < EMITTERS_NUMBER; i++)
            {
                m_soundEmitters[i]         = new MyEntity3DSoundEmitter(this);
                m_soundEmitters[i].Force3D = true;
            }
        }
Example #24
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            var ob = objectBuilder as MyObjectBuilder_SmallGatlingGun;

            var weaponBlockDefinition = BlockDefinition as MyWeaponBlockDefinition;

            if (weaponBlockDefinition != null)
            {
                m_ammoInventory = new MyInventory(weaponBlockDefinition.InventoryMaxVolume, new Vector3(0.4f, 0.4f, 0.4f), MyInventoryFlags.CanReceive, this);
            }
            else
            {
                m_ammoInventory = new MyInventory(64.0f / 1000, new Vector3(0.4f, 0.4f, 0.4f), MyInventoryFlags.CanReceive, this);
            }

            base.Init(objectBuilder, cubeGrid);

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

            m_ammoInventory.ContentsChanged += AmmoInventory_ContentsChanged;

            GetBarrelAndMuzzle();
            //if (m_ammoPerShotConsumption == 0)
            //    m_ammoPerShotConsumption = (MyFixedPoint)((45.0f / (1000.0f / MyGatlingConstants.SHOT_INTERVAL_IN_MILISECONDS)) / m_gunBase.WeaponProperties.AmmoMagazineDefinition.Capacity);

            m_useConveyorSystem = ob.UseConveyorSystem;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                weaponBlockDefinition.ResourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_SHIP_GUN,
                () => ResourceSink.MaxRequiredInput);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;
            ResourceSink.Update();
            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));
        }
Example #25
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();
            if (IsBeingHacked)
            {
                PrivateDescription.Clear();
                SendChangeDescriptionMessage(PrivateDescription, false);
            }
            ResourceSink.Update();
            if (IsFunctional && IsWorking)
            {
                if (ShowTextOnScreen && IsInRange() == false)
                {
                    if (!m_isOutofRange)
                    {
                        m_isOutofRange = true;
                        ReleaseRenderTexture();
                    }
                    return;
                }

                if (ShowTextOnScreen && (NeedsToDrawText() || m_isOutofRange || m_forceUpdateText))
                {
                    m_descriptionChanged     = false;
                    m_forceUpdateText        = false;
                    m_fontColorChanged       = false;
                    m_fontSizeChanged        = false;
                    m_backgroundColorChanged = false;
                    Render.RenderTextToTexture(EntityId, ShowTextFlag == ShowTextOnScreenFlag.PUBLIC ? m_publicDescription.ToString() : m_privateDescription.ToString(), FontSize * BlockDefinition.TextureResolution / DEFAULT_RESOLUTION, FontColor, BackgroundColor, BlockDefinition.TextureResolution, BlockDefinition.TextureAspectRadio);
                    FailedToRenderTexture = false;
                }

                m_isOutofRange = false;

                if (ShowTextOnScreen == false)
                {
                    UpdateTexture();
                }
            }
        }
Example #26
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            ++m_updateCounter;

            int sourceUpdateFrames = (m_updateCounter - m_lastOutputUpdateTime);
            int sinkUpdateFrames   = (m_updateCounter - m_lastInputUpdateTime);

            float gasInput  = GasInputPerUpdate * sinkUpdateFrames;
            float gasOutput = GasOutputPerUpdate * sourceUpdateFrames;

            float totalTransfer = gasInput - gasOutput + m_nextGasTransfer;

            if (CheckTransfer(totalTransfer))
            {
                Transfer(totalTransfer);
                ResourceSink.Update();
                m_lastOutputUpdateTime = m_updateCounter;
                m_lastInputUpdateTime  = m_updateCounter;
            }
        }
Example #27
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var sinkComp = new MyResourceSinkComponent();

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

            var jumpDriveBuilder = objectBuilder as MyObjectBuilder_JumpDrive;

            NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.BEFORE_NEXT_FRAME | VRage.ModAPI.MyEntityUpdateEnum.EACH_FRAME | VRage.ModAPI.MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_storedPower = jumpDriveBuilder.StoredPower;
            if (m_storedPower >= BlockDefinition.PowerNeededForJump)
            {
                m_storedPower = BlockDefinition.PowerNeededForJump;
            }

            m_storedJumpTarget = jumpDriveBuilder.JumpTarget;
            if (jumpDriveBuilder.JumpTarget != null)
            {
                m_jumpTarget = MySession.Static.Gpss.GetGps(jumpDriveBuilder.JumpTarget.Value);
            }

            m_jumpDistanceRatio = jumpDriveBuilder.JumpRatio;
            m_isRecharging      = jumpDriveBuilder.Recharging;

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

            ResourceSink.Update();
            UpdateEmissivity();
        }
Example #28
0
        public override void UpdateBeforeSimulation()
        {
            if (m_stateChange && ((m_open && 1f - m_currOpening < EPSILON) || (!m_open && m_currOpening < EPSILON)))
            {
                //END OF MOVEMENT
                if (m_soundEmitter.IsPlaying && m_soundEmitter.Loop)
                {
                    m_soundEmitter.StopSound(false);
                }
                m_currSpeed = 0;
                ResourceSink.Update();
                RaisePropertiesChanged();
                if (!m_open)
                {   //finished closing - they are airtight now
                    var handle = DoorStateChanged;
                    if (handle != null)
                    {
                        handle(m_open);
                    }
                }
                m_stateChange = false;
            }
            if (m_soundEmitter != null)
            {
                if (Enabled && ResourceSink.IsPowered && m_currSpeed != 0)
                {
                    StartSound(m_sound);
                }
                else
                {
                    m_soundEmitter.StopSound(false);
                }
            }

            base.UpdateBeforeSimulation();
            UpdateCurrentOpening();

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }
Example #29
0
        void ComponentStack_IsFunctionalChanged()
        {
            SourceComp.Enabled = CanStore;
            ResourceSink.Update();
            FilledRatio = 0;

            if (MySession.Static.CreativeMode)
            {
                SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, Capacity);
            }
            else
            {
                SourceComp.SetRemainingCapacityByType(BlockDefinition.StoredGasId, FilledRatio * Capacity);
            }

            // ResourceDistributor could be null if the grid is falling apart for whatever reason (collisions, explosions, etc)
            if (CubeGrid != null && CubeGrid.GridSystems != null && CubeGrid.GridSystems.ResourceDistributor != null)
            {
                CubeGrid.GridSystems.ResourceDistributor.ConveyorSystem_OnPoweredChanged(); // Hotfix TODO
            }
            UdpateText();
        }
        private void RecomputeGyroParameters()
        {
            m_gyrosChanged = false;

            float oldRequirement = m_maxRequiredPowerInput;

            m_maxGyroForce                   = 0.0f;
            m_maxOverrideForce               = 0.0f;
            m_maxRequiredPowerInput          = 0.0f;
            m_overrideTargetVelocity         = Vector3.Zero;
            m_overrideAccelerationRampFrames = null;
            foreach (var gyro in m_gyros)
            {
                if (IsUsed(gyro))
                {
                    if (!gyro.GyroOverride || AutopilotEnabled)
                    {
                        m_maxGyroForce += gyro.MaxGyroForce;
                    }
                    else
                    {
                        m_overrideTargetVelocity += gyro.GyroOverrideVelocityGrid * gyro.MaxGyroForce;
                        m_maxOverrideForce       += gyro.MaxGyroForce;
                    }
                    m_maxRequiredPowerInput += gyro.RequiredPowerInput;
                }
            }
            if (m_maxOverrideForce != 0.0f)
            {
                m_overrideTargetVelocity /= m_maxOverrideForce;
            }

            ResourceSink.MaxRequiredInput = m_maxRequiredPowerInput;
            ResourceSink.Update();

            UpdateAutomaticDeactivation();
        }