コード例 #1
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;
                PowerReceiver.Update();
                RaisePropertiesChanged();
                if (!m_open)
                {   //finished closing - they are airtight now
                    var handle = DoorStateChanged;
                    if (handle != null)
                    {
                        handle(m_open);
                    }
                }
                m_stateChange = false;
            }
            if (Enabled && PowerReceiver.IsPowered && m_currSpeed != 0)
            {
                StartSound(m_sound);
            }
            else
            {
                m_soundEmitter.StopSound(false);
            }

            base.UpdateBeforeSimulation();
            UpdateCurrentOpening();

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }
コード例 #2
0
        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;
            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 + m_maxGyroForce) != 0.0f)
            {
                m_overrideTargetVelocity /= (m_maxOverrideForce + m_maxGyroForce);
            }

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

            UpdateAutomaticDeactivation();
        }
コード例 #3
0
 public override void OnBuildSuccess(long builtBy)
 {
     PowerReceiver.Update();
     UpdateHavokCollisionSystemID(CubeGrid.Physics.HavokCollisionSystemID);
     base.OnBuildSuccess(builtBy);
 }
コード例 #4
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 && PowerReceiver != null && PowerReceiver.IsPowered && 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)))
            {
                PowerReceiver.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_COLLISION_PRIMITIVES)
            {
                for (int i = 0; i < m_subparts.Count; i++)
                {
                    m_subparts[i].DebugDraw();
                    m_subparts[i].DebugDrawPhysics();
                }
            }
        }
コード例 #5
0
ファイル: MyAirVent.cs プロジェクト: Tyrsis/SpaceEngineers-1
 protected override void OnEnabledChanged()
 {
     base.OnEnabledChanged();
     PowerReceiver.Update();
     UpdateEmissivity();
 }
コード例 #6
0
 public override void UpdateAfterSimulation()
 {
     base.UpdateAfterSimulation();
     PowerReceiver.Update();
 }
コード例 #7
0
 protected override void OnEnabledChanged()
 {
     PowerReceiver.Update();
     base.OnEnabledChanged();
 }
コード例 #8
0
 void MyOxygenTank_IsWorkingChanged(MyCubeBlock obj)
 {
     PowerReceiver.Update();
     UpdateEmissivity();
 }
コード例 #9
0
 void MyShipToolBase_EnabledChanged(MyTerminalBlock obj)
 {
     PowerReceiver.Update();
 }
コード例 #10
0
 public void EndShoot(MyShootActionEnum action)
 {
     m_drillBase.StopDrill();
     m_tryingToDrill = false;
     PowerReceiver.Update();
 }
コード例 #11
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            //MyRenderProxy.DebugDrawSphere(m_gunBase.PositionMuzzleWorld, 0.2f, new Vector3(1, 0, 0), 1.0f, true);

            m_targetGrid           = null;
            m_targetDestroyable    = null;
            m_targetFloatingObject = null;
            m_targetCharacter      = null;

            if (Owner == null)
            {
                return;
            }

            var   entitiesInRange    = m_sensor.EntitiesInRange;
            int   closestEntityIndex = 0;
            float closestDistance    = float.MaxValue;

            if (entitiesInRange != null && entitiesInRange.Count > 0)
            {
                int i = 0;
                foreach (var entity in entitiesInRange.Values)
                {
                    var targetGrid = entity.Entity as MyCubeGrid;
                    var distanceSq = (float)Vector3D.DistanceSquared(entity.DetectionPoint, m_gunBase.GetMuzzleWorldPosition());
                    if (entity.Entity.Physics != null && entity.Entity.Physics.Enabled)
                    {
                        if (distanceSq < closestDistance)
                        {
                            m_targetGrid           = targetGrid;
                            m_targetDistanceSq     = (float)distanceSq;
                            m_targetDestroyable    = entity.Entity as IMyDestroyableObject;
                            m_targetFloatingObject = entity.Entity as MyFloatingObject;
                            m_targetCharacter      = entity.Entity as MyCharacter;
                            closestDistance        = m_targetDistanceSq;
                            closestEntityIndex     = i;
                        }
                    }
                    ++i;
                }
            }

            if (m_targetGrid != null)
            {
                m_targetPosition = entitiesInRange.Values.ElementAt(closestEntityIndex).DetectionPoint;
                var invWorld     = m_targetGrid.PositionComp.GetWorldMatrixNormalizedInv();
                var gridLocalPos = Vector3D.Transform(m_targetPosition, invWorld);
                var gridSpacePos = Vector3I.Round(gridLocalPos / m_targetGrid.GridSize);
                m_targetGrid.FixTargetCube(out m_targetCube, gridLocalPos / m_targetGrid.GridSize);

                var head        = PositionComp.WorldMatrix;
                var aimToMuzzle = Vector3D.Normalize(m_targetPosition - m_gunBase.GetMuzzleWorldPosition());
                if (Vector3.Dot(aimToMuzzle, head.Forward) > 0)
                {
                    m_targetDistanceSq = 0;
                }
                else
                {
                    m_targetDistanceSq = (float)Vector3D.DistanceSquared(m_targetPosition, m_gunBase.GetMuzzleWorldPosition());
                }
            }
            PowerReceiver.Update();

            if (IsShooting && !PowerReceiver.IsPowered)
            {
                EndShoot(MyShootActionEnum.PrimaryAction);
            }

            UpdateEffect();
            CheckEffectType();

            //MyTrace.Watch("MyEngineerToolBase.RequiredPowerInput", RequiredPowerInput);
        }
コード例 #12
0
 public override void OnBuildSuccess(long builtBy)
 {
     PowerReceiver.Update();
     base.OnBuildSuccess(builtBy);
 }
コード例 #13
0
 void OnBroadcastRadiusChanged()
 {
     PowerReceiver.Update();
     UpdateText();
 }
コード例 #14
0
 protected virtual void UpdatePower()
 {
     PowerReceiver.Update();
 }
コード例 #15
0
 void OnBroadcastRadiusChanged()
 {
     PowerReceiver.Update();
     RaisePropertiesChanged();
     UpdateText();
 }
コード例 #16
0
 public void EndShoot(MyShootActionEnum action)
 {
     m_wantsToDrill = false;
     PowerReceiver.Update();
 }
コード例 #17
0
        public override void UpdateAfterSimulation100()
        {
            base.UpdateAfterSimulation100();

            if (IsFunctional)
            {
                if (SemiautoEnabled)
                {
                    if (CurrentStoredPower == 0)
                    {
                        ProducerEnabled = false;
                        SyncObject.SendProducerEnableChange(false);
                        SyncObject.SendSemiautoEnableChange(SemiautoEnabled);
                    }
                    if (CurrentStoredPower == MaxStoredPower)
                    {
                        ProducerEnabled = true;
                        SyncObject.SendProducerEnableChange(true);
                        SyncObject.SendSemiautoEnableChange(SemiautoEnabled);
                    }
                }

                PowerReceiver.Update();
                RefreshRemainingCapacity();

                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 (!ProducerEnabled)
                        {
                            StorePower(timeDelta, PowerReceiver.CurrentInput);
                        }
                        else
                        {
                            ConsumePower(timeDelta);
                        }
                    }
                }
                else
                {
                    if ((Sync.IsServer && IsFunctional && !CubeGrid.GridSystems.ControlSystem.IsControlled) ||
                        CubeGrid.GridSystems.ControlSystem.IsLocallyControlled)
                    {
                        if (!ProducerEnabled)
                        {
                            StorePower(timeDelta, (3600 * MaxStoredPower) / 8f);
                        }
                        else
                        if (ProducerEnabled)
                        {
                            RefreshRemainingCapacity();
                            UpdateIsWorking();
                            if (!HasCapacityRemaining)
                            {
                                return;
                            }
                            PowerReceiver.Update();
                            CalculateOutputTimeRemaining();
                        }
                    }
                }

                if (!ProducerEnabled)
                {
                    CalculateInputTimeRemaining();
                }
                else
                {
                    CalculateOutputTimeRemaining();
                }
            }
        }
コード例 #18
0
ファイル: MyButtonPanel.cs プロジェクト: caomw/SpaceEngineers
 void ComponentStack_IsFunctionalChanged()
 {
     PowerReceiver.Update();
     UpdateEmissivity();
 }
コード例 #19
0
 public override void OnAddedToScene(object source)
 {
     base.OnAddedToScene(source);
     UpdateEmissivity();
     PowerReceiver.Update();
 }
コード例 #20
0
 void MyBatteryBlock_IsWorkingChanged(MyCubeBlock obj)
 {
     UpdateMaxOutputAndEmissivity();
     PowerReceiver.Update();
 }
コード例 #21
0
 void IsPoweredChanged()
 {
     PowerReceiver.Update();
     UpdateText();
     UpdateEmissivity();
 }
コード例 #22
0
 protected override void OnEnabledChanged()
 {
     UpdateMaxOutputAndEmissivity();
     PowerReceiver.Update();
     base.OnEnabledChanged();
 }
コード例 #23
0
        private void UpdateThrusts()
        {
            Matrix invWorldRot = m_grid.PositionComp.GetWorldMatrixNormalizedInv().GetOrientation();

            Vector3 localVelocity   = Vector3.Transform(m_grid.Physics.LinearVelocity, ref invWorldRot);
            Vector3 positiveControl = Vector3.Clamp(ControlThrust, Vector3.Zero, Vector3.One);
            Vector3 negativeControl = Vector3.Clamp(ControlThrust, -Vector3.One, Vector3.Zero);
            Vector3 slowdownControl = Vector3.Zero;

            if (DampenersEnabled)
            {
                slowdownControl = Vector3.IsZeroVector(ControlThrust, 0.001f) * Vector3.IsZeroVector(m_totalThrustOverride);
            }

            Thrust = negativeControl * m_maxNegativeThrust + positiveControl * m_maxPositiveThrust;
            Thrust = Vector3.Clamp(Thrust, -m_maxNegativeThrust, m_maxPositiveThrust);

            const float STOPPING_TIME        = 0.5f;
            var         slowdownAcceleration = -localVelocity / STOPPING_TIME;
            var         slowdownThrust       = slowdownAcceleration * m_grid.Physics.Mass * slowdownControl;

            Thrust = Vector3.Clamp(Thrust + slowdownThrust, -m_maxNegativeThrust * MyFakes.SLOWDOWN_FACTOR_THRUST_MULTIPLIER, m_maxPositiveThrust * MyFakes.SLOWDOWN_FACTOR_THRUST_MULTIPLIER);

            // Calculate ratio of usage for different directions.
            Vector3 thrustPositive = Thrust / (m_maxPositiveThrust + 0.0000001f);
            Vector3 thrustNegative = -Thrust / (m_maxNegativeThrust + 0.0000001f);

            thrustPositive = Vector3.Clamp(thrustPositive, Vector3.Zero, Vector3.One * MyConstants.MAX_THRUST);
            thrustNegative = Vector3.Clamp(thrustNegative, Vector3.Zero, Vector3.One * MyConstants.MAX_THRUST);



            // When using joystick, there may be fractional values, not just 0 and 1.
            float requiredPower = 0;

            requiredPower += (thrustPositive.X > 0) ? thrustPositive.X * GetMaxRequirement(Vector3I.Left) : 0;
            requiredPower += (thrustPositive.Y > 0) ? thrustPositive.Y * GetMaxRequirement(Vector3I.Down) : 0;
            requiredPower += (thrustPositive.Z > 0) ? thrustPositive.Z * GetMaxRequirement(Vector3I.Forward) : 0;
            requiredPower += (thrustNegative.X > 0) ? thrustNegative.X * GetMaxRequirement(Vector3I.Right) : 0;
            requiredPower += (thrustNegative.Y > 0) ? thrustNegative.Y * GetMaxRequirement(Vector3I.Up) : 0;
            requiredPower += (thrustNegative.Z > 0) ? thrustNegative.Z * GetMaxRequirement(Vector3I.Backward) : 0;
            requiredPower += m_totalThrustOverridePower;
            if (requiredPower < m_minPowerInputTotal)
            {
                requiredPower = m_minPowerInputTotal;
            }

            // Setting this notifies power distributor who updates power input and thus changes SuppliedPowerRatio.
            RequiredPowerInput = requiredPower;
            PowerReceiver.Update();

            Thrust += m_totalThrustOverride;
            Thrust *= PowerReceiver.SuppliedRatio;
            Thrust *= MyFakes.THRUST_FORCE_RATIO;

            if (m_grid.GridSystems.ControlSystem.IsLocallyControlled || (!m_grid.GridSystems.ControlSystem.IsControlled && Sync.IsServer) || (false && Sync.IsServer))
            {
                if (Thrust.LengthSquared() > 0.001f)
                {
                    if (m_grid.Physics.Enabled)
                    {
                        m_grid.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, Thrust, null, null);
                    }
                }

                const float stoppingVelocitySq = 0.001f * 0.001f;
                if (m_grid.Physics.Enabled)
                {
                    if (m_grid.Physics.LinearVelocity != Vector3.Zero && m_grid.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq && m_grid.Physics.RigidBody.IsActive)
                    {
                        m_grid.Physics.LinearVelocity = Vector3.Zero;
                    }
                }
            }

            UpdateThrustStrength(m_thrustsByDirection[Vector3I.Left], thrustPositive.X, PowerReceiver.SuppliedRatio);
            UpdateThrustStrength(m_thrustsByDirection[Vector3I.Down], thrustPositive.Y, PowerReceiver.SuppliedRatio);
            UpdateThrustStrength(m_thrustsByDirection[Vector3I.Forward], thrustPositive.Z, PowerReceiver.SuppliedRatio);
            UpdateThrustStrength(m_thrustsByDirection[Vector3I.Right], thrustNegative.X, PowerReceiver.SuppliedRatio);
            UpdateThrustStrength(m_thrustsByDirection[Vector3I.Up], thrustNegative.Y, PowerReceiver.SuppliedRatio);
            UpdateThrustStrength(m_thrustsByDirection[Vector3I.Backward], thrustNegative.Z, PowerReceiver.SuppliedRatio);
        }
コード例 #24
0
 private void ComponentStack_IsFunctionalChanged()
 {
     PowerReceiver.Update();
 }
コード例 #25
0
 public void UpdateBeforeSimulation10()
 {
     PowerReceiver.Update();
 }