//thruster composition + ship category
        private void UpdateCategory()
        {
            if (m_initialized && m_shipGrid != null && m_shipGrid.Physics != null && m_shipGrid.IsStatic == false && m_definition != null)
            {
                if (m_distanceToShip < m_definition.MaxUpdateRange_sq)
                {
                    if (m_shipThrusters == null)
                    {
                        m_shipThrusters = m_shipGrid.Components.Get <MyEntityThrustComponent>();
                    }
                    if (m_shipWheels == null)
                    {
                        m_shipWheels = m_shipGrid.GridSystems.WheelSystem;
                    }

                    CalculateShipCategory();
                    if (m_isDebris == false && m_shipState != ShipStateEnum.NoPower && (m_singleThrusterTypeShip == false || ShipHasChanged ||
                                                                                        m_shipThrusters == null || m_shipThrusters.FinalThrust == Vector3.Zero || (m_shipWheels != null && m_shipWheels.HasWorkingWheels(false))))
                    {
                        CalculateThrusterComposition();
                    }

                    if (m_shipSoundSource == null)
                    {
                        m_shipSoundSource = m_shipGrid;
                    }
                    if (m_shipGrid.MainCockpit != null && m_shipGrid.GridSizeEnum == MyCubeSize.Small)
                    {
                        m_shipSoundSource = m_shipGrid.MainCockpit;
                    }

                    if (m_shipGrid.GridSizeEnum == MyCubeSize.Large && MySession.Static != null && MySession.Static.LocalCharacter != null)
                    {
                        if (MySession.Static.Settings.RealisticSound == false ||
                            (MySession.Static.LocalCharacter.AtmosphereDetectorComp != null && (MySession.Static.LocalCharacter.AtmosphereDetectorComp.InAtmosphere || MySession.Static.LocalCharacter.AtmosphereDetectorComp.InShipOrStation)))
                        {
                            BoundingSphereD playerSphere = new BoundingSphereD(MySession.Static.LocalCharacter.PositionComp.GetPosition(), m_definition.LargeShipDetectionRadius);
                            m_shipGrid.GetBlocksInsideSphere(ref playerSphere, m_detectedBlocks);
                            m_insideShip = m_detectedBlocks.Count > 0;
                        }
                        else
                        {
                            m_insideShip = false;
                        }
                    }
                }
            }
        }
        private void ActivateCommon()
        {
            BoundingSphereD globalSphere = new BoundingSphereD(Vector3D.Transform(m_detectorSphere.Center, CubeGrid.WorldMatrix), m_detectorSphere.Radius);

            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
            {
                MyRenderProxy.DebugDrawSphere(globalSphere.Center, (float)globalSphere.Radius, Color.Red.ToVector3(), 1.0f, false);
            }

            m_isActivatedOnSomething = false;

            foreach (var entry in m_entitiesInContact)
            {
                MyCubeGrid  grid      = entry.Key as MyCubeGrid;
                MyCharacter character = entry.Key as MyCharacter;

                if (grid != null)
                {
                    m_tempBlocksBuffer.Clear();
                    grid.GetBlocksInsideSphere(ref globalSphere, m_tempBlocksBuffer);
                    m_blocksToActivateOn.UnionWith(m_tempBlocksBuffer);
                }
                if (character != null && Sync.IsServer)
                {
                    MyDamageType damageType = MyDamageType.Drill;
                    if (this is IMyShipGrinder)
                    {
                        damageType = MyDamageType.Grind;
                    }
                    else if (this is IMyShipWelder)
                    {
                        damageType = MyDamageType.Weld;
                    }

                    character.DoDamage(20, damageType, true, attackerId: EntityId);
                }
            }

            m_isActivatedOnSomething |= Activate(m_blocksToActivateOn);

            m_activateCounter++;
            m_lastTimeActivate = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            PlayLoopSound(m_isActivatedOnSomething);

            m_blocksToActivateOn.Clear();
        }
Beispiel #3
0
        public void Update100()
        {
            m_distanceToShip = m_initialized && m_shipGrid.Physics != null ? (m_shouldPlay2D ? 0 : (float)Vector3D.DistanceSquared(MySector.MainCamera.Position, m_shipGrid.PositionComp.GetPosition())) : MAX_UPDATE_RANGE_SQ + 1;
            if (m_initialized && m_shipGrid.Physics != null && m_shipGrid.IsStatic == false && m_distanceToShip < MAX_UPDATE_RANGE_SQ)
            {
                if (m_shipThrusters == null)
                {
                    m_shipThrusters = m_shipGrid.Components.Get <MyEntityThrustComponent>();
                }
                if (m_shipWheels == null)
                {
                    m_shipWheels = m_shipGrid.GridSystems.WheelSystem;
                }

                CalculateShipCategory();
                if (m_shipCategory != ShipTypeEnum.Debris && m_shipState != ShipStateEnum.NoPower && (m_singleThrusterTypeShip == false || ShipHasChanged ||
                                                                                                      m_shipThrusters == null || m_shipThrusters.FinalThrust == Vector3.Zero || m_shipWheels.HasWorkingWheels(false)))
                {
                    CalculateThrusterComposition();
                }

                if (m_shipSoundSource == null)
                {
                    m_shipSoundSource = m_shipGrid;
                }
                if (m_shipGrid.MainCockpit != null && m_shipGrid.GridSizeEnum == MyCubeSize.Small)
                {
                    m_shipSoundSource = m_shipGrid.MainCockpit;
                }

                if (m_shipGrid.GridSizeEnum == MyCubeSize.Large && MySession.Static.LocalCharacter != null)
                {
                    BoundingSphereD       playerSphere   = new BoundingSphereD(MySession.Static.LocalCharacter.PositionComp.GetPosition(), LARGE_SHIP_DETECTION_RADIUS);
                    HashSet <MySlimBlock> detectedBlocks = new HashSet <MySlimBlock>();
                    m_shipGrid.GetBlocksInsideSphere(ref playerSphere, detectedBlocks);
                    m_insideShip = detectedBlocks.Count > 0;
                }
            }
            for (int i = 0; i < m_emitters.Length; i++)
            {
                m_emitters[i].Entity = m_shipSoundSource;
                m_emitters[i].Update();
            }
        }
        private static MyShipConnector TryFindConnectorInGrid(ref BoundingSphereD sphere, MyCubeGrid grid, MyShipConnector thisConnector = null)
        {
            m_tmpBlockSet.Clear();
            grid.GetBlocksInsideSphere(ref sphere, m_tmpBlockSet);

            foreach (var block in m_tmpBlockSet)
            {
                if (block.FatBlock == null || !(block.FatBlock is MyShipConnector)) continue;

                var connector = block.FatBlock as MyShipConnector;
                if (connector.InConstraint) continue;
                if (connector == thisConnector) continue;
                if (!connector.IsWorking) continue;
                if (!connector.FriendlyWithBlock(thisConnector)) continue;

                m_tmpBlockSet.Clear();
                return connector;
            }

            m_tmpBlockSet.Clear();
            return null;
        }
        private void ActivateCommon()
        {
            BoundingSphereD globalSphere = new BoundingSphereD(Vector3D.Transform(m_detectorSphere.Center, CubeGrid.WorldMatrix), m_detectorSphere.Radius);

            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
            {
                MyRenderProxy.DebugDrawSphere(globalSphere.Center, (float)globalSphere.Radius, Color.Red.ToVector3(), 1.0f, false);
            }

            m_isActivatedOnSomething = false;
            ProfilerShort.Begin("Query");
            var res = MyEntities.GetTopMostEntitiesInSphere(ref globalSphere);

            m_entitiesInContact.Clear();
            foreach (MyEntity entity in res)
            {
                var rootEntity = entity.GetTopMostParent();
                if (CanInteractWith(rootEntity))
                {
                    m_entitiesInContact.Add(rootEntity);
                }
            }
            res.Clear();
            ProfilerShort.End();

            //TODO:cache blocks on this grid
            foreach (var entry in m_entitiesInContact)
            {
                MyCubeGrid  grid      = entry as MyCubeGrid;
                MyCharacter character = entry as MyCharacter;

                if (grid != null)
                {
                    m_tempBlocksBuffer.Clear();
                    grid.GetBlocksInsideSphere(ref globalSphere, m_tempBlocksBuffer);
                    m_blocksToActivateOn.UnionWith(m_tempBlocksBuffer);
                }
                if (character != null && Sync.IsServer)
                {
                    MyStringHash damageType = MyDamageType.Drill;
                    if (this is IMyShipGrinder)
                    {
                        damageType = MyDamageType.Grind;
                    }
                    else if (this is IMyShipWelder)
                    {
                        damageType = MyDamageType.Weld;
                    }
                    if (globalSphere.Intersects(character.PositionComp.WorldAABB))
                    {
                        character.DoDamage(20, damageType, true, attackerId: EntityId);
                    }
                }
            }

            m_isActivatedOnSomething |= Activate(m_blocksToActivateOn);

            m_activateCounter++;
            m_lastTimeActivate = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            PlayLoopSound(m_isActivatedOnSomething);

            m_blocksToActivateOn.Clear();
        }
Beispiel #6
0
        public void Update100()
        {
            //thruster composition + ship category
            m_distanceToShip = m_initialized && m_shipGrid.Physics != null ? (m_shouldPlay2D ? 0 : (float)Vector3D.DistanceSquared(MySector.MainCamera.Position, m_shipGrid.PositionComp.GetPosition())) : float.MaxValue;
            if (m_initialized && m_shipGrid.Physics != null && m_shipGrid.IsStatic == false)
            {
                if (m_distanceToShip < m_definition.MaxUpdateRange_sq)
                {
                    if (m_shipThrusters == null)
                    {
                        m_shipThrusters = m_shipGrid.Components.Get <MyEntityThrustComponent>();
                    }
                    if (m_shipWheels == null)
                    {
                        m_shipWheels = m_shipGrid.GridSystems.WheelSystem;
                    }

                    CalculateShipCategory();
                    if (m_isDebris == false && m_shipState != ShipStateEnum.NoPower && (m_singleThrusterTypeShip == false || ShipHasChanged ||
                                                                                        m_shipThrusters == null || m_shipThrusters.FinalThrust == Vector3.Zero || m_shipWheels.HasWorkingWheels(false)))
                    {
                        CalculateThrusterComposition();
                    }

                    if (m_shipSoundSource == null)
                    {
                        m_shipSoundSource = m_shipGrid;
                    }
                    if (m_shipGrid.MainCockpit != null && m_shipGrid.GridSizeEnum == MyCubeSize.Small)
                    {
                        m_shipSoundSource = m_shipGrid.MainCockpit;
                    }

                    if (m_shipGrid.GridSizeEnum == MyCubeSize.Large && MySession.Static.LocalCharacter != null)
                    {
                        BoundingSphereD playerSphere = new BoundingSphereD(MySession.Static.LocalCharacter.PositionComp.GetPosition(), m_definition.LargeShipDetectionRadius);
                        m_shipGrid.GetBlocksInsideSphere(ref playerSphere, m_detectedBlocks);
                        m_insideShip = m_detectedBlocks.Count > 0;
                    }
                }
            }

            //sound emitter update
            for (int i = 0; i < m_emitters.Length; i++)
            {
                m_emitters[i].Entity = m_shipSoundSource;
                m_emitters[i].Update();
            }

            //wheel contact point callbacks
            if (m_shipGrid.Physics != null && m_shipWheels != null && m_shipWheels.WheelCount > 0)
            {
                bool start = m_distanceToShip < m_definition.WheelsCallbackRangeCreate_sq && m_isDebris == false;
                bool stop  = m_distanceToShip > m_definition.WheelsCallbackRangeRemove_sq || m_isDebris;
                if ((start || stop) && (m_lastWheelUpdateStart != start || m_lastWheelUpdateStop != stop))
                {
                    foreach (var motor in m_shipWheels.Wheels)
                    {
                        if (motor.RotorGrid == null || motor.RotorGrid.Physics == null)
                        {
                            continue;
                        }
                        if (motor.RotorGrid.HasShipSoundEvents == false && start)
                        {
                            motor.RotorGrid.Physics.RigidBody.ContactPointCallback += RigidBody_ContactPointCallback;
                            motor.RotorGrid.Physics.RigidBody.CallbackLimit         = 1;
                            motor.RotorGrid.OnClosing         += RotorGrid_OnClosing;
                            motor.RotorGrid.HasShipSoundEvents = true;
                        }
                        else if (motor.RotorGrid.HasShipSoundEvents && stop)
                        {
                            motor.RotorGrid.HasShipSoundEvents = false;
                            motor.RotorGrid.Physics.RigidBody.ContactPointCallback -= RigidBody_ContactPointCallback;
                            motor.RotorGrid.OnClosing -= RotorGrid_OnClosing;
                        }
                    }
                    m_lastWheelUpdateStart = start;
                    m_lastWheelUpdateStop  = stop;
                    if (start && m_shipWheelsAction == false)
                    {
                        m_shipWheels.OnMotorUnregister += m_shipWheels_OnMotorUnregister;
                        m_shipWheelsAction              = true;
                    }
                    else if (stop && m_shipWheelsAction)
                    {
                        m_shipWheels.OnMotorUnregister -= m_shipWheels_OnMotorUnregister;
                        m_shipWheelsAction              = false;
                    }
                }
            }
        }