public FunctionalBlockEntity( CubeGridEntity parent, MyObjectBuilder_FunctionalBlock definition, Object backingObject )
            : base(parent, definition, backingObject)
        {
            m_enabled = definition.Enabled;

            m_powerReceiver = new PowerReceiver( ActualObject, Parent.PowerManager, InternalGetPowerReceiver( ), new Func<float>( InternalPowerReceiverCallback ) );
        }
示例#2
0
        protected virtual void StopShooting()
        {
            m_wantsToActivate        = false;
            m_isActivated            = false;
            m_isActivatedOnSomething = false;

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

            m_shootHeatup = 0;

            StopEffects();
            StopLoopSound();
        }
示例#3
0
 private void ComponentStack_IsFunctionalChanged()
 {
     PowerReceiver.Update();
     if (IsFunctional)
     {
         if (ShowTextOnScreen == false)
         {
             Render.ChangeTexture(GetPathForID(DEFAULT_ONLINE_TEXTURE));
         }
         m_previousTextureID = null;
         m_forceUpdateText   = ShowTextOnScreen;
     }
     else
     {
         if (ShowTextOnScreen)
         {
             Render.ReleaseRenderTexture();
         }
         Render.ChangeTexture(GetPathForID(DEFAULT_OFFLINE_TEXTURE));
     }
 }
        private void RecomputeWheelParameters()
        {
            m_wheelsChanged = false;

            float oldRequirement = m_maxRequiredPowerInput;

            m_maxRequiredPowerInput = 0.0f;

            foreach (var motor in m_wheels)
            {
                if (!IsUsed(motor))
                {
                    continue;
                }

                m_maxRequiredPowerInput += motor.RequiredPowerInput;
            }

            PowerReceiver.MaxRequiredInput = m_maxRequiredPowerInput;
            PowerReceiver.Update();
        }
示例#5
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();
            if (IsBeingHacked)
            {
                PrivateDescription.Clear();
                SyncObject.SendChangeDescriptionMessage(PrivateDescription, false);
            }
            PowerReceiver.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();
                }
            }
        }
示例#6
0
        private void UpdatePowerAndThrustStrength(Vector3 thrust, bool updateThrust)
        {
            // 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();

            if (updateThrust)
            {
                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);
            }
        }
示例#7
0
        public virtual void Shoot(MyShootActionEnum action, Vector3 direction)
        {
            if (action != MyShootActionEnum.PrimaryAction)
            {
                return;
            }

            m_lastTimeShoot = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            m_shootFrameCounter++;
            m_tryingToShoot = true;
            PowerReceiver.Update();
            if (!PowerReceiver.IsPowered)
            {
                CurrentEffect = 0;
                return;
            }

            m_activated = true;

            var targetBlock = GetTargetBlock();

            if (targetBlock == null)
            {
                CurrentEffect = 2;
                ShakeAmount   = m_handItemDef.ShakeAmountNoTarget;
            }

            int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            if (targetBlock != null)
            {
                ShakeAmount   = m_handItemDef.ShakeAmountTarget;
                CurrentEffect = 1;
            }
            return;
        }
        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();
        }
示例#9
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;
        }
示例#10
0
 public void EndShoot(MyShootActionEnum action)
 {
     m_wantsToDrill = false;
     PowerReceiver.Update();
 }
示例#11
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();
                }
            }
        }
示例#12
0
 public override void OnBuildSuccess(long builtBy)
 {
     PowerReceiver.Update();
     UpdateHavokCollisionSystemID(CubeGrid.Physics.HavokCollisionSystemID);
     base.OnBuildSuccess(builtBy);
 }
 public override void UpdateAfterSimulation()
 {
     base.UpdateAfterSimulation();
     PowerReceiver.Update();
 }
示例#14
0
 public FunctionalBlockEntity(CubeGridEntity parent, MyObjectBuilder_FunctionalBlock definition, Object backingObject)
     : base(parent, definition, backingObject)
 {
     m_powerReceiver = new PowerReceiver(ActualObject, Parent.PowerManager, InternalGetPowerReceiver(), new Func <float>(InternalPowerReceiverCallback));
 }
示例#15
0
 void MyBatteryBlock_IsWorkingChanged(MyCubeBlock obj)
 {
     UpdateMaxOutputAndEmissivity();
     PowerReceiver.Update();
 }
示例#16
0
 void OnBroadcastRadiusChanged()
 {
     PowerReceiver.Update();
     RaisePropertiesChanged();
     UpdateText();
 }
示例#17
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);
        }
示例#18
0
        protected bool RunReflectionUnitTests()
        {
            bool result = true;

            if (!BaseObject.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseObject reflection validation failed!");
            }

            if (!BaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseEntity reflection validation failed!");
            }

            if (!BaseEntityNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseEntityNetworkManager reflection validation failed!");
            }

            if (!CubeGridEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridEntity reflection validation failed!");
            }

            if (!CubeGridNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridNetworkManager reflection validation failed!");
            }

            if (!CubeBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeBlockEntity reflection validation failed!");
            }

            if (!TerminalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TerminalBlockEntity reflection validation failed!");
            }

            if (!FunctionalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FunctionalBlockEntity reflection validation failed!");
            }

            if (!SectorObjectManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SectorObjectManager reflection validation failed!");
            }

            if (!CharacterEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CharacterEntity reflection validation failed!");
            }

            if (!InventoryEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("InventoryEntity reflection validation failed!");
            }

            if (!InventoryItemEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("InventoryItemEntity reflection validation failed!");
            }

            if (!PlayerMap.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PlayerMap reflection validation failed!");
            }

            if (!PlayerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PlayerManager reflection validation failed!");
            }

            if (!WorldManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("WorldManager reflection validation failed!");
            }

            if (!RadioManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RadioManager reflection validation failed!");
            }

            if (!RadioManagerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RadioManagerNetworkManager reflection validation failed!");
            }

            if (!PowerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerManager reflection validation failed!");
            }

            if (!FactionsManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FactionsManager reflection validation failed!");
            }

            if (!Faction.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("Faction reflection validation failed!");
            }

            if (!PowerProducer.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerProducer reflection validation failed!");
            }

            if (!PowerReceiver.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerReceiver reflection validation failed!");
            }

            result &= RunCubeBlockReflectionTests();

            if (result)
            {
                Console.WriteLine("All main types passed reflection unit tests!");
            }

            return(result);
        }
示例#19
0
 void IsPoweredChanged()
 {
     PowerReceiver.Update();
     UpdateText();
     UpdateEmissivity();
 }
示例#20
0
 public override void OnBuildSuccess(long builtBy)
 {
     PowerReceiver.Update();
     base.OnBuildSuccess(builtBy);
 }
示例#21
0
        protected bool RunEntityReflectionUnitTests()
        {
            bool result = true;

            if (!BaseObject.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseObject reflection validation failed!");
            }

            if (!BaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseEntity reflection validation failed!");
            }

            if (!BaseEntityNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BaseEntityNetworkManager reflection validation failed!");
            }

            if (!CubeGridEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridEntity reflection validation failed!");
            }

            if (!CubeGridManagerManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridManagerManager reflection validation failed!");
            }

            if (!CubeGridNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridNetworkManager reflection validation failed!");
            }

            if (!CubeGridThrusterManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeGridThrusterManager reflection validation failed!");
            }

            if (!SectorObjectManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SectorObjectManager reflection validation failed!");
            }

            if (!CharacterEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CharacterEntity reflection validation failed!");
            }

            if (!CharacterEntityNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CharacterEntityNetworkManager reflection validation failed!");
            }

            if (!FloatingObject.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FloatingObject reflection validation failed!");
            }

            if (!FloatingObjectManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FloatingObjectManager reflection validation failed!");
            }

            if (!InventoryEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("InventoryEntity reflection validation failed!");
            }

            if (!InventoryItemEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("InventoryItemEntity reflection validation failed!");
            }

            if (!PowerProducer.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerProducer reflection validation failed!");
            }

            if (!PowerReceiver.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PowerReceiver reflection validation failed!");
            }

            if (!VoxelMap.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("VoxelMap reflection validation failed!");
            }

            if (!VoxelMapMaterialManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("VoxelMapMaterialManager reflection validation failed!");
            }

            if (result)
            {
                Console.WriteLine("All entity types passed reflection unit tests!");
            }

            return(result);
        }
示例#22
0
 void ComponentStack_IsFunctionalChanged()
 {
     PowerReceiver.Update();
     UpdateEmissivity();
 }
 protected override void OnEnabledChanged()
 {
     PowerReceiver.Update();
     base.OnEnabledChanged();
 }
示例#24
0
 void MyShipToolBase_EnabledChanged(MyTerminalBlock obj)
 {
     PowerReceiver.Update();
 }
示例#25
0
 protected override void OnEnabledChanged()
 {
     UpdateMaxOutputAndEmissivity();
     PowerReceiver.Update();
     base.OnEnabledChanged();
 }
示例#26
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();
                }
            }
        }
示例#27
0
 void OnBroadcastRadiusChanged()
 {
     PowerReceiver.Update();
     UpdateText();
 }
示例#28
0
 protected override void OnEnabledChanged()
 {
     base.OnEnabledChanged();
     PowerReceiver.Update();
     UpdateEmissivity();
 }
 protected virtual void UpdatePower()
 {
     PowerReceiver.Update();
 }
 private void ComponentStack_IsFunctionalChanged()
 {
     PowerReceiver.Update();
 }
示例#31
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);
        }