private void ChangeTarget()
        {
            Vector3D cameraPos, cameraDir;

            if (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity)
            {
                var headMatrix = MySession.ControlledEntity.GetHeadMatrix(true, true);
                cameraPos = headMatrix.Translation;
                cameraDir = headMatrix.Forward;
            }
            else
            {
                cameraPos = MySector.MainCamera.Position;
                cameraDir = MySector.MainCamera.WorldMatrix.Forward;
            }

            m_tmpHitInfos.Clear();
            MyPhysics.CastRay(cameraPos, cameraPos + cameraDir * 20, m_tmpHitInfos, MyPhysics.ObjectDetectionCollisionLayer);
            if (m_tmpHitInfos.Count == 0)
            {
                return;
            }
            foreach (var hitInfo in m_tmpHitInfos)
            {
                var ent = hitInfo.HkHitInfo.GetHitEntity() as MyCharacter;
                if (ent != null)
                {
                    MyAgentBot bot;
                    if (TryGetBotForCharacter(ent, out bot) && bot.BotDefinition.Commandable)
                    {
                        ChangeBotBehavior(bot);
                    }
                }
            }
        }
Exemplo n.º 2
0
        //Game and editor shares this method
        public void MoveAndRotatePlayerOrCamera()
        {
            MyCameraControllerEnum cce  = MySession.GetCameraControllerEnum();
            bool movementAllowedInPause = cce == MyCameraControllerEnum.Spectator;
            bool rotationAllowedInPause = movementAllowedInPause ||
                                          (cce == MyCameraControllerEnum.ThirdPersonSpectator && MyInput.Static.IsAnyAltKeyPressed());

            bool    allowRoll         = !MySessionComponentVoxelHand.Static.BuildMode;
            bool    allowMove         = !MySessionComponentVoxelHand.Static.BuildMode && !MyCubeBuilder.Static.IsBuildMode;
            float   rollIndicator     = allowRoll ? MyInput.Static.GetRoll() : 0;
            Vector2 rotationIndicator = MyInput.Static.GetRotation();

            VRageMath.Vector3 moveIndicator = allowMove ? MyInput.Static.GetPositionDelta() : Vector3.Zero;

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////  Decide who is moving
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //First move control objects
            if (MySession.ControlledEntity != null)// && MySession.ControlledObject != MySession.Static.CameraController)
            {
                if (MySandboxGame.IsPaused)
                {
                    if (!movementAllowedInPause && !rotationAllowedInPause)
                    {
                        return;
                    }

                    if (!rotationAllowedInPause)
                    {
                        rotationIndicator = Vector2.Zero;
                    }
                    rollIndicator = 0.0f;
                }
                if (MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.UserControlled)
                {
                    MySpectatorCameraController.Static.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                }
                else
                {
                    if (!MySession.Static.CameraController.IsInFirstPersonView)
                    {
                        MyThirdPersonSpectator.Static.UpdateZoom();
                    }

                    if (!MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND))
                    {
                        MySession.ControlledEntity.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                    }
                    else
                    {
                        MySession.ControlledEntity.MoveAndRotate(moveIndicator, Vector2.Zero, rollIndicator);
                        if (!MySession.Static.CameraController.IsInFirstPersonView)
                        {
                            MyThirdPersonSpectator.Static.SaveSettings();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void OnUnregisteredFromGridSystems()
        {
            base.OnUnregisteredFromGridSystems();

            if (m_pilot != null)
            {
                //sync_ControlledEntity_Used();

                var pilot = m_pilot;

                if (!MyEntities.CloseAllowed)
                {
                    RemovePilot();
                    pilot.DoDamage(1000, MyDamageType.Unknown, false);
                }
                else
                if (MySession.Static.CameraController == this)
                {
                    MySession.SetCameraController(MySession.GetCameraControllerEnum(), m_pilot);
                }
            }

            if (CubeGrid.GridSystems.OxygenSystem != null && m_conveyorEndpoint != null)
            {
                CubeGrid.GridSystems.OxygenSystem.UnregisterOxygenBlock(this);
            }
        }
Exemplo n.º 4
0
        protected override void UpdateThrusts()
        {
            base.UpdateThrusts();

            if (Character != null &&
                Character.Physics != null &&
                Jetpack.TurnedOn &&
                (MySession.LocalCharacter == Character ||
                 (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity && (MySector.MainCamera.IsInFrustum(Character.PositionComp.WorldAABB) ||
                                                                                           (Character.PositionComp.GetPosition() - MySector.MainCamera.Position).LengthSquared() < 100f))))
            {
                if (FinalThrust.LengthSquared() > 0.001f)
                {
                    Character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, FinalThrust, null, null);
                }

                const float stoppingVelocitySq = 0.001f * 0.001f;
                if (Character.Physics.Enabled)
                {
                    if (Character.Physics.LinearVelocity != Vector3.Zero && Character.Physics.LinearVelocity.LengthSquared() < stoppingVelocitySq)
                    {
                        Character.Physics.LinearVelocity = Vector3.Zero;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void ChangeCamera()
        {
            if (MySession.Static.Settings.Enable3rdPersonView)
            {
                m_storedCamera.Controller = MySession.GetCameraControllerEnum();
                m_storedCamera.Distance   = MySession.GetCameraTargetDistance();

                MySession.SetCameraController(MyCameraControllerEnum.ThirdPersonSpectator);
                MySession.SetCameraTargetDistance(2f);
            }
        }
 private static MatrixD GetPasteMatrix()
 {
     if (MySession.ControlledEntity != null &&
         (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator))
     {
         return(MySession.ControlledEntity.GetHeadMatrix(true));
     }
     else
     {
         return(MySector.MainCamera.WorldMatrix);
     }
 }
Exemplo n.º 7
0
 public override void UpdateAfterSimulation()
 {
     base.UpdateAfterSimulation();
     if (Owner != null && Owner.ControllerInfo.IsLocallyHumanControlled())
     {
         if (MySession.Static.SurvivalMode && (MySession.GetCameraControllerEnum() != MyCameraControllerEnum.Spectator || MyFinalBuildConstants.IS_OFFICIAL))
         {
             var character = ((MyCharacter)this.CharacterInventory.Owner);
             MyCubeBuilder.Static.MaxGridDistanceFrom = character.PositionComp.GetPosition() + character.WorldMatrix.Up * 1.8f;
         }
         else
         {
             MyCubeBuilder.Static.MaxGridDistanceFrom = null;
         }
     }
 }
Exemplo n.º 8
0
        private void TrySpawnBot()
        {
            Vector3D cameraPos, cameraDir;

            if (MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.ThirdPersonSpectator || MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.Entity)
            {
                var headMatrix = MySession.ControlledEntity.GetHeadMatrix(true, true);
                cameraPos = headMatrix.Translation;
                cameraDir = headMatrix.Forward;
            }
            else
            {
                cameraPos = MySector.MainCamera.Position;
                cameraDir = MySector.MainCamera.WorldMatrix.Forward;
            }

            List <MyPhysics.HitInfo> hitInfos = new List <MyPhysics.HitInfo>();

            MyPhysics.CastRay(cameraPos, cameraPos + cameraDir * 100, hitInfos, MyPhysics.ObjectDetectionCollisionLayer);
            if (hitInfos.Count == 0)
            {
                return;
            }

            MyPhysics.HitInfo?closestValidHit = null;
            foreach (var hitInfo in hitInfos)
            {
                var ent = hitInfo.HkHitInfo.Body.GetEntity();
                if (ent is MyCubeGrid)
                {
                    closestValidHit = hitInfo;
                    break;
                }
                else if (ent is MyVoxelMap)
                {
                    closestValidHit = hitInfo;
                    break;
                }
            }

            if (closestValidHit.HasValue)
            {
                Vector3D position = closestValidHit.Value.Position;
                MyAIComponent.Static.SpawnNewBot(BotToSpawn, position);
            }
        }
Exemplo n.º 9
0
        public void SwitchCamera()
        {
            MySession.Static.CameraController.IsInFirstPersonView = !MySession.Static.CameraController.IsInFirstPersonView;

            if (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator)
            {
                MyEntityCameraSettings settings = null;
                if (MySession.Static.Cameras.TryGetCameraSettings(MySession.LocalHumanPlayer.Id, MySession.ControlledEntity.Entity.EntityId, out settings))
                {
                    MyThirdPersonSpectator.Static.ResetDistance(settings.Distance);
                }
                else
                {
                    MyThirdPersonSpectator.Static.RecalibrateCameraPosition();
                }
            }

            MySession.SaveControlledEntityCameraSettings(MySession.Static.CameraController.IsInFirstPersonView);
        }
        public override void UpdateAfterSimulation10()
        {
            if (m_useObjectNotification != null && !m_usingContinuously)
            {
                MyHud.Notifications.Add(m_useObjectNotification);
            }

            m_usingContinuously = false;

            if (MySession.ControlledEntity == Character && !Character.IsSitting && !Character.IsDead)
            {
                DoDetection(MySession.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator);
            }
            else
            {
                if (MySession.ControlledEntity == Character)
                {
                    MyHud.SelectedObjectHighlight.Visible = false;
                }
            }
        }
Exemplo n.º 11
0
        private bool TestPlacement()
        {
            bool retval = true;

            for (int i = 0; i < PreviewGrids.Count; ++i)
            {
                var grid     = PreviewGrids[i];
                var settings = m_settings.GetGridPlacementSettings(grid);

                if (MySession.Static.SurvivalMode && !MyCubeBuilder.DeveloperSpectatorIsBuilding)
                {
                    if (i == 0 && !MyCubeBuilder.Static.DynamicMode)
                    {
                        MatrixD invMatrix = grid.PositionComp.WorldMatrixNormalizedInv;
                        if (!MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref invMatrix, (BoundingBoxD)grid.PositionComp.LocalAABB, grid.GridSize, MyCubeBuilder.Static.IntersectionDistance) ||
                            MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Spectator)
                        {
                            m_visible = false;
                            return(false);
                        }
                    }

                    if (!MySession.Static.SimpleSurvival && MySession.ControlledEntity is MyCharacter)
                    {
                        foreach (var block in grid.GetBlocks())
                        {
                            retval &= (MySession.ControlledEntity as MyCharacter).CanStartConstruction(block.BlockDefinition);
                            if (!retval)
                            {
                                break;
                            }
                        }
                    }

                    if (i == 0 && MySession.Static.SimpleSurvival)
                    {
                        retval = retval && MyCubeBuilder.Static.CanBuildBlockSurvivalTime();
                    }

                    if (!retval)
                    {
                        return(false);
                    }
                }

                if (MyCubeBuilder.Static.DynamicMode)
                {
                    if (!m_dynamicBuildAllowed)
                    {
                        var settingsLocal = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.PastingSettings.LargeGrid : MyPerGameSettings.PastingSettings.SmallGrid;

                        foreach (var block in grid.GetBlocks())
                        {
                            Vector3      minLocal  = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize;
                            Vector3      maxLocal  = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize;
                            BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal);
                            retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, aabbLocal, true);
                        }
                    }
                }
                else if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions)
                {
                    var hitGrid = m_hitEntity as MyCubeGrid;

                    bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small;

                    if (smallOnLargeGrid)
                    {
                        retval = retval && MyCubeGrid.TestPlacementArea(grid, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, false /*, hitGrid*/);
                    }
                    else
                    {
                        retval = retval && TestGridPlacementOnGrid(grid, ref settings, hitGrid);
                    }
                }
                else if (i == 0 && m_hitEntity is MyVoxelMap)
                {
                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock is MyCompoundCubeBlock)
                        {
                            MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                            foreach (var blockInCompound in compoundBlock.GetBlocks())
                            {
                                retval = retval && TestBlockPlacementArea(blockInCompound, ref settings, false);
                                if (!retval)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            retval = retval && TestBlockPlacementArea(block, ref settings, false);
                        }

                        if (!retval)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var settingsLocal = m_settings.GetGridPlacementSettings(grid, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode);
                    retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, (BoundingBoxD)grid.PositionComp.LocalAABB, false);
                }

                BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB;
                MatrixD      invGridWorlMatrix = grid.PositionComp.GetWorldMatrixNormalizedInv();

                // Character collisions.
                if (MySector.MainCamera != null)
                {
                    Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix);
                    retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains;
                }

                if (retval)
                {
                    m_tmpCollisionPoints.Clear();
                    MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints);
                    foreach (var pt in m_tmpCollisionPoints)
                    {
                        Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix);
                        retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains;
                        if (!retval)
                        {
                            break;
                        }
                    }
                }
            }

            return(retval);
        }
Exemplo n.º 12
0
        private void PlaceAreaMarker()
        {
            Vector3D cameraPos, cameraDir;

            if (MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.ThirdPersonSpectator || MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.Entity)
            {
                var headMatrix = MySession.ControlledEntity.GetHeadMatrix(true, true);
                cameraPos = headMatrix.Translation;
                cameraDir = headMatrix.Forward;
            }
            else
            {
                cameraPos = MySector.MainCamera.Position;
                cameraDir = MySector.MainCamera.WorldMatrix.Forward;
            }

            List <MyPhysics.HitInfo> hitInfos = new List <MyPhysics.HitInfo>();

            MyPhysics.CastRay(cameraPos, cameraPos + cameraDir * 100, hitInfos, MyPhysics.ObjectDetectionCollisionLayer);
            if (hitInfos.Count == 0)
            {
                return;
            }

            MyPhysics.HitInfo?closestValidHit = null;
            foreach (var hitInfo in hitInfos)
            {
                var ent = hitInfo.HkHitInfo.Body.GetEntity();
                if (ent is MyCubeGrid)
                {
                    closestValidHit = hitInfo;
                    break;
                }
                else if (ent is MyVoxelMap)
                {
                    closestValidHit = hitInfo;
                    break;
                }
            }

            if (closestValidHit.HasValue)
            {
                Vector3D position = closestValidHit.Value.Position;
                MyAreaMarkerDefinition definition = AreaMarkerDefinition;
                //MyDefinitionManager.Static.TryGetDefinition(new MyDefinitionId(typeof(MyObjectBuilder_AreaMarkerDefinition), "ForestingArea"), out definition);

                m_tmpAreas.Clear();
                MyPlaceAreas.GetAllAreas(m_tmpAreas);

                foreach (var area in m_tmpAreas)
                {
                    if (area.AreaType == AreaMarkerDefinition.Id.SubtypeId)
                    {
                        area.Entity.Close();
                    }
                }
                m_tmpAreas.Clear();

                Debug.Assert(definition != null, "Area marker definition cannot be null!");
                if (definition == null)
                {
                    return;
                }

                var forward = Vector3D.Reject(cameraDir, Vector3D.Up);

                if (Vector3D.IsZero(forward))
                {
                    forward = Vector3D.Forward;
                }

                var flag = new MyAreaMarker(new MyPositionAndOrientation(position, Vector3D.Normalize(forward), Vector3D.Up), definition);

                MyEntities.Add(flag);
            }
        }
Exemplo n.º 13
0
        public override void Draw()
        {
            base.Draw();
            if (MySession.ControlledEntity == m_character && !m_character.IsSitting && !m_character.IsDead)
            {
                m_character.RayCast(MySession.GetCameraControllerEnum() != MyCameraControllerEnum.ThirdPersonSpectator);
            }
            else
            {
                if (m_character == MySession.ControlledEntity)
                {
                    MyHud.SelectedObjectHighlight.Visible = false;
                }
            }
            //VRageRender.MyRenderProxy.DebugDrawOBB(safeObbWithCollisionExtents, Vector3.One, 1.0f, false, false);

            //CalculateTransforms();
            //CalculateDependentMatrices();

            //MySector.MainCamera.SetViewMatrix(MySession.Static.CameraController.GetViewMatrix());

            UpdateCharacterSkeleton();

            VRageRender.MyRenderProxy.SetCharacterTransforms(RenderObjectIDs[0], m_character.BoneRelativeTransforms);

            //VRageRender.MyRenderProxy.AddSwappableObject(this);

            Matrix headMatrix = m_character.GetHeadMatrix(false);
            //UpdateLightPosition();

            Vector3 position      = m_light.Position;
            Vector3 forwardVector = m_light.ReflectorDirection;
            Vector3 leftVector    = headMatrix.Left;
            Vector3 upVector      = headMatrix.Up;

            float reflectorLength    = MyCharacter.REFLECTOR_BILLBOARD_LENGTH * 0.4f * 0.16f;
            float reflectorThickness = MyCharacter.REFLECTOR_BILLBOARD_THICKNESS * 0.08f;
            //float reflectorRadiusForAdditive = 0.25f;//0.65f;

            Vector3 color = new Vector3(m_light.ReflectorColor);

            Vector3 glarePosition          = position + forwardVector * 0.28f;
            var     dot                    = Vector3.Dot(Vector3.Normalize(MySector.MainCamera.Position - glarePosition), forwardVector);
            float   angle                  = 1 - Math.Abs(dot);
            float   alphaGlareAlphaBlended = (float)Math.Pow(1 - angle, 2);
            float   alphaGlareAdditive     = (float)Math.Pow(1 - angle, 2);
            float   alphaCone              = (1 - (float)Math.Pow(1 - angle, 30)) * 0.5f;

            float reflectorRadiusForAlphaBlended = MathHelper.Lerp(0.1f, 0.5f, alphaGlareAlphaBlended); //3.5f;

            //  Multiply alpha by reflector level (and not the color), because if we multiply the color and let alpha unchanged, reflector cune will be drawn as very dark cone, but still visible
            var reflectorLevel = m_character.CurrentLightPower;

            m_light.ReflectorIntensity = reflectorLevel;

            alphaCone *= reflectorLevel * 0.2f;
            alphaGlareAlphaBlended *= reflectorLevel * 0.1f;
            alphaGlareAdditive     *= reflectorLevel * 0.8f;

            float distance = Vector3.Distance(m_character.PositionComp.GetPosition(), MySector.MainCamera.Position);

            if (!m_character.IsInFirstPersonView && distance < MyCharacter.LIGHT_GLARE_MAX_DISTANCE && reflectorLevel > 0)
            {
                float alpha = MathHelper.Clamp((MyCharacter.LIGHT_GLARE_MAX_DISTANCE - 10.0f) / distance, 0, 1);

                if (reflectorLength > 0 && reflectorThickness > 0)
                {
                    if (m_leftGlare != null)
                    {
                        MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha,
                                                               m_leftGlare.Position,
                                                               m_leftGlare.ReflectorDirection, reflectorLength, reflectorThickness);
                    }

                    if (m_rightGlare != null)
                    {
                        MyTransparentGeometry.AddLineBillboard("ReflectorConeCharacter", new Vector4(color, 1.0f) * alphaCone * alpha,
                                                               m_rightGlare.Position,
                                                               m_rightGlare.ReflectorDirection, reflectorLength, reflectorThickness);
                    }
                }

                if (m_leftGlare != null)
                {
                    MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha,
                                                            m_leftGlare.Position, reflectorRadiusForAlphaBlended * 0.3f, 0);
                }

                if (m_rightGlare != null)
                {
                    MyTransparentGeometry.AddPointBillboard("ReflectorGlareAlphaBlended", new Vector4(color, 1.0f) * alphaGlareAlphaBlended * alpha,
                                                            m_rightGlare.Position, reflectorRadiusForAlphaBlended * 0.3f, 0);
                }
            }

            DrawJetpackThrusts(m_character.UpdateCalled());

            if (m_character.Hierarchy.Parent != null)
            {
                if (m_leftGlare != null && m_leftGlare.LightOn == true)
                {
                    m_leftGlare.LightOn = false;
                    m_leftGlare.GlareOn = false;
                    m_leftGlare.UpdateLight();
                }

                if (m_rightGlare != null && m_rightGlare.LightOn == true)
                {
                    m_rightGlare.LightOn = false;
                    m_rightGlare.GlareOn = false;
                    m_rightGlare.UpdateLight();
                }
            }
            else
            {
                if (m_leftGlare != null && m_leftGlare.LightOn == false)
                {
                    m_leftGlare.LightOn = true;
                    m_leftGlare.GlareOn = true;
                    m_leftGlare.UpdateLight();
                }

                if (m_rightGlare != null && m_rightGlare.LightOn == true)
                {
                    m_rightGlare.LightOn = true;
                    m_rightGlare.GlareOn = true;
                    m_rightGlare.UpdateLight();
                }
            }

            if (MySession.ControlledEntity == m_character)
            {
                if (m_character.IsDead && m_character.CurrentRespawnCounter > 0)
                {
                    DrawBlood(1);
                }

                if (!m_character.IsDead && m_currentHitIndicatorCounter > 0)
                {
                    m_currentHitIndicatorCounter -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                    if (m_currentHitIndicatorCounter < 0)
                    {
                        m_currentHitIndicatorCounter = 0;
                    }

                    float alpha = m_currentHitIndicatorCounter / HIT_INDICATOR_LENGTH;

                    DrawBlood(alpha);
                }

                if (m_character.HealthRatio <= MyCharacter.LOW_HEALTH_RATIO && !m_character.IsDead)
                {
                    float alpha = MathHelper.Clamp(MyCharacter.LOW_HEALTH_RATIO - m_character.HealthRatio, 0, 1) / MyCharacter.LOW_HEALTH_RATIO + 0.3f;
                    DrawBlood(alpha);
                }
            }

            //DebugDraw();
        }
Exemplo n.º 14
0
        public MyTomasInputComponent()
        {
            AddShortcut(MyKeys.Delete, true, true, false, false,
                        () => "Delete all characters",
                        delegate
            {
                foreach (var obj in MyEntities.GetEntities().OfType <MyCharacter>())
                {
                    if (obj == MySession.ControlledEntity)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.Spectator);
                    }
                    obj.Close();
                }

                foreach (var obj in MyEntities.GetEntities().OfType <MyCubeGrid>())
                {
                    foreach (var obj2 in obj.GetBlocks())
                    {
                        if (obj2.FatBlock is MyCockpit)
                        {
                            var cockpit = obj2.FatBlock as MyCockpit;
                            if (cockpit.Pilot != null)
                            {
                                cockpit.Pilot.Close();
                            }
                        }
                    }
                }
                return(true);
            });

            AddShortcut(MyKeys.NumPad4, true, false, false, false,
                        () => "Spawn cargo ship or barbarians",
                        delegate
            {
                var theEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnCargoShip"));
                if (theEvent == null)
                {
                    theEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnBarbarians"));
                }
                if (theEvent != null)
                {
                    MyGlobalEvents.RemoveGlobalEvent(theEvent);
                    theEvent.SetActivationTime(TimeSpan.FromSeconds(1));
                    MyGlobalEvents.AddGlobalEvent(theEvent);
                }
                return(true);
            });

            AddShortcut(MyKeys.NumPad5, true, false, false, false,
                        () => "Spawn random meteor",
                        delegate
            {
                var camera        = MySector.MainCamera;
                var target        = camera.Position + MySector.MainCamera.ForwardVector * 20.0f;
                var spawnPosition = target + MySector.DirectionToSunNormalized * 1000.0f;

                if (MyUtils.GetRandomFloat(0.0f, 1.0f) < 0.2f)
                {
                    MyMeteor.SpawnRandomLarge(spawnPosition, -MySector.DirectionToSunNormalized);
                }
                else
                {
                    MyMeteor.SpawnRandomSmall(spawnPosition, -MySector.DirectionToSunNormalized);
                }
                return(true);
            });

            AddShortcut(MyKeys.NumPad8, true, false, false, false,
                        () => "Switch control to next entity",
                        delegate
            {
                if (MySession.ControlledEntity != null)
                { //we already are controlling this object
                    var cameraController = MySession.GetCameraControllerEnum();
                    if (cameraController != MyCameraControllerEnum.Entity && cameraController != MyCameraControllerEnum.ThirdPersonSpectator)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.Entity, MySession.ControlledEntity.Entity);
                    }
                    else
                    {
                        var entities       = MyEntities.GetEntities().ToList();
                        int lastKnownIndex = entities.IndexOf(MySession.ControlledEntity.Entity);

                        var entitiesList = new List <MyEntity>();
                        if (lastKnownIndex + 1 < entities.Count)
                        {
                            entitiesList.AddRange(entities.GetRange(lastKnownIndex + 1, entities.Count - lastKnownIndex - 1));
                        }

                        if (lastKnownIndex != -1)
                        {
                            entitiesList.AddRange(entities.GetRange(0, lastKnownIndex + 1));
                        }

                        MyCharacter newControlledObject = null;

                        for (int i = 0; i < entitiesList.Count; i++)
                        {
                            var character = entitiesList[i] as MyCharacter;
                            if (character != null)
                            {
                                newControlledObject = character;
                                break;
                            }
                        }

                        if (newControlledObject != null)
                        {
                            MySession.LocalHumanPlayer.Controller.TakeControl(newControlledObject);
                        }
                    }
                }

                return(true);
            });


            AddShortcut(MyKeys.NumPad7, true, false, false, false,
                        () => "Use next ship",
                        delegate
            {
                MyCharacterInputComponent.UseNextShip();
                return(true);
            });

            AddShortcut(MyKeys.NumPad9, true, false, false, false,
                        () => "Debug new grid screen",
                        delegate
            {
                MyGuiSandbox.AddScreen(new DebugNewGridScreen());
                return(true);
            });

            AddShortcut(MyKeys.N, true, false, false, false,
                        () => "Refill all batteries",
                        delegate
            {
                foreach (var entity in MyEntities.GetEntities())
                {
                    MyCubeGrid grid = entity as MyCubeGrid;
                    if (grid != null)
                    {
                        foreach (var block in grid.GetBlocks())
                        {
                            MyBatteryBlock battery = block.FatBlock as MyBatteryBlock;
                            if (battery != null)
                            {
                                battery.CurrentStoredPower = battery.MaxStoredPower;
                            }
                        }
                    }
                }
                return(true);
            });

            AddShortcut(MyKeys.U, true, false, false, false,
                        () => "Spawn new character",
                        delegate
            {
                var character = MyCharacterInputComponent.SpawnCharacter();
                return(true);
            });


            AddShortcut(MyKeys.NumPad2, true, false, false, false,
                        () => "Merge static grids",
                        delegate
            {
                // Try to merge all static large grids
                HashSet <MyCubeGrid> ignoredGrids = new HashSet <MyCubeGrid>();
                while (true)
                {
                    // Flag that we need new entities enumeration
                    bool needNewEntitites = false;

                    foreach (var entity in MyEntities.GetEntities())
                    {
                        MyCubeGrid grid = entity as MyCubeGrid;
                        if (grid != null && grid.IsStatic && grid.GridSizeEnum == MyCubeSize.Large)
                        {
                            if (ignoredGrids.Contains(grid))
                            {
                                continue;
                            }

                            List <MySlimBlock> blocks = grid.GetBlocks().ToList();
                            foreach (var block in blocks)
                            {
                                var mergedGrid = grid.DetectMerge(block);
                                if (mergedGrid == null)
                                {
                                    continue;
                                }

                                needNewEntitites = true;
                                // Grid merged to other grid? Then break and loop all entities again.
                                if (mergedGrid != grid)
                                {
                                    break;
                                }
                            }

                            if (!needNewEntitites)
                            {
                                ignoredGrids.Add(grid);
                            }
                        }

                        if (needNewEntitites)
                        {
                            break;
                        }
                    }

                    if (!needNewEntitites)
                    {
                        break;
                    }
                }
                return(true);
            });

            AddShortcut(MyKeys.Add, true, false, false, false,
                        () => "Increase wheel animation speed",
                        delegate
            {
                USE_WHEEL_ANIMATION_SPEED += 0.05f;
                return(true);
            });

            AddShortcut(MyKeys.Subtract, true, false, false, false,
                        () => "Decrease wheel animation speed",
                        delegate
            {
                USE_WHEEL_ANIMATION_SPEED -= 0.05f;
                return(true);
            });

            AddShortcut(MyKeys.Divide, true, false, false, false,
                        () => "Show model texture names",
                        delegate
            {
                MyFakes.ENABLE_DEBUG_DRAW_TEXTURE_NAMES = !MyFakes.ENABLE_DEBUG_DRAW_TEXTURE_NAMES;
                return(true);
            });

            AddShortcut(MyKeys.NumPad1, true, false, false, false,
                        () => "Throw from spectator: " + Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW,
                        delegate
            {
                Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW = !Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW;
                return(true);
            });

            AddShortcut(MyKeys.F2, true, false, false, false, () => "Spectator to next small grid", () => SpectatorToNextGrid(MyCubeSize.Small));
            AddShortcut(MyKeys.F3, true, false, false, false, () => "Spectator to next large grid", () => SpectatorToNextGrid(MyCubeSize.Large));
        }
Exemplo n.º 15
0
        //  This method is called every update (but only if application has focus)
        public override void HandleUnhandledInput(bool receivedFocusInThisUpdate)
        {
            if (MyInput.Static.ENABLE_DEVELOPER_KEYS || (MySession.Static != null && MySession.Static.Settings.EnableSpectator) || (MyMultiplayer.Static != null && MySession.LocalHumanPlayer != null && MyMultiplayer.Static.IsAdmin(MySession.LocalHumanPlayer.Id.SteamId)))
            {
                //Set camera to player
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_NONE))
                {
                    if (MySession.ControlledEntity != null)
                    { //we already are controlling this object
                        if (MyFinalBuildConstants.IS_OFFICIAL)
                        {
                            SetCameraController();
                        }
                        else
                        {
                            var cameraController = MySession.GetCameraControllerEnum();
                            if (cameraController != MyCameraControllerEnum.Entity && cameraController != MyCameraControllerEnum.ThirdPersonSpectator)
                            {
                                SetCameraController();
                            }
                            else
                            {
                                var entities       = MyEntities.GetEntities().ToList();
                                int lastKnownIndex = entities.IndexOf(MySession.ControlledEntity.Entity);

                                var entitiesList = new List <MyEntity>();
                                if (lastKnownIndex + 1 < entities.Count)
                                {
                                    entitiesList.AddRange(entities.GetRange(lastKnownIndex + 1, entities.Count - lastKnownIndex - 1));
                                }

                                if (lastKnownIndex != -1)
                                {
                                    entitiesList.AddRange(entities.GetRange(0, lastKnownIndex + 1));
                                }

                                MyCharacter newControlledObject = null;

                                for (int i = 0; i < entitiesList.Count; i++)
                                {
                                    var character = entitiesList[i] as MyCharacter;
                                    if (character != null && !character.IsDead)
                                    {
                                        newControlledObject = character;
                                        break;
                                    }
                                }

                                if (MySession.LocalHumanPlayer != null && newControlledObject != null)
                                {
                                    MySession.LocalHumanPlayer.Controller.TakeControl(newControlledObject);
                                }
                            }

                            // We could have activated the cube builder in spectator, so deactivate it now
                            if (MyCubeBuilder.Static.IsActivated && !(MySession.ControlledEntity is MyCharacter))
                            {
                                MyCubeBuilder.Static.Deactivate();
                            }
                        }
                    }
                }

                //Set camera to following third person
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_DELTA))
                {
                    if (MySession.ControlledEntity != null)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.SpectatorDelta);
                    }
                }

                //Set camera to spectator
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_FREE))
                {
                    if (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle || Sync.IsServer)
                    {
                        if (MySession.GetCameraControllerEnum() != MyCameraControllerEnum.Spectator)
                        {
                            MySession.SetCameraController(MyCameraControllerEnum.Spectator);
                        }
                        else if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS = !MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS;
                        }

                        if (MyInput.Static.IsAnyCtrlKeyPressed() && MySession.ControlledEntity != null)
                        {
                            MySpectator.Static.Position = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition() + MySpectator.Static.ThirdPersonCameraDelta;
                            MySpectator.Static.Target   = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition();
                        }
                    }
                }

                //Set camera to static spectator, non movable
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SPECTATOR_STATIC))
                {
                    if (MySession.ControlledEntity != null)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.SpectatorFixed);

                        if (MyInput.Static.IsAnyCtrlKeyPressed())
                        {
                            MySpectator.Static.Position = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition() + MySpectator.Static.ThirdPersonCameraDelta;
                            MySpectator.Static.Target   = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition();
                        }
                    }
                }

                //Open console
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.CONSOLE) && MyInput.Static.IsAnyAltKeyPressed())
                {
                    MyGuiScreenConsole.Show();
                }
            }

            if (MyDefinitionErrors.ShouldShowModErrors)
            {
                MyDefinitionErrors.ShouldShowModErrors = false;
                MyGuiSandbox.ShowModErrors();
            }

            // Switch view - cockpit on/off, third person
            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.CAMERA_MODE) && CanSwitchCamera)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                SwitchCamera();
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.HELP_SCREEN))
            {
                if (MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    switch (MySandboxGame.Config.DebugComponentsInfo)
                    {
                    case MyDebugComponent.MyDebugComponentInfoState.NoInfo:
                        MySandboxGame.Config.DebugComponentsInfo = MyDebugComponent.MyDebugComponentInfoState.EnabledInfo;
                        break;

                    case MyDebugComponent.MyDebugComponentInfoState.EnabledInfo:
                        MySandboxGame.Config.DebugComponentsInfo = MyDebugComponent.MyDebugComponentInfoState.FullInfo;
                        break;

                    case MyDebugComponent.MyDebugComponentInfoState.FullInfo:
                        MySandboxGame.Config.DebugComponentsInfo = MyDebugComponent.MyDebugComponentInfoState.NoInfo;
                        break;
                    }

                    MySandboxGame.Config.Save();
                }
                else
                if (MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    MyGuiSandbox.AddScreen(MyGuiScreenGamePlay.ActiveGameplayScreen = MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.HelpScreen));
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.TOGGLE_HUD))
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                MyHud.MinimalHud = !MyHud.MinimalHud;
            }

            if (MyPerGameSettings.SimplePlayerNames && MyInput.Static.IsNewGameControlPressed(MyControlsSpace.BROADCASTING))
            {
                MyHud.LocationMarkers.Visible = !MyHud.LocationMarkers.Visible;
            }

            var controlledObject        = MySession.ControlledEntity;
            var currentCameraController = MySession.Static.CameraController;

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.MISSION_SETTINGS) && MyGuiScreenGamePlay.ActiveGameplayScreen == null &&
                MyPerGameSettings.Game == Sandbox.Game.GameEnum.SE_GAME &&
                MyFakes.ENABLE_MISSION_TRIGGERS &&
                MySession.Static.Settings.ScenarioEditMode)
            {
                MyGuiSandbox.AddScreen(new Sandbox.Game.Screens.MyGuiScreenMissionTriggers());
            }

            MyStringId context = controlledObject != null ? controlledObject.ControlContext : MySpaceBindingCreator.CX_BASE;

            bool handledByUseObject = false;

            if (MySession.ControlledEntity is VRage.Game.Entity.UseObject.IMyUseObject)
            {
                handledByUseObject = (MySession.ControlledEntity as VRage.Game.Entity.UseObject.IMyUseObject).HandleInput();
            }

            if (controlledObject != null && !handledByUseObject)
            {
                if (!MySandboxGame.IsPaused)
                {
                    if (context == MySpaceBindingCreator.CX_BUILD_MODE || context == MySpaceBindingCreator.CX_CHARACTER || context == MySpaceBindingCreator.CX_SPACESHIP)
                    {
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
                        {
                            if (MyToolbarComponent.CurrentToolbar.ShouldActivateSlot)
                            {
                                MyToolbarComponent.CurrentToolbar.ActivateStagedSelectedItem();
                            }
                            else
                            {
                                controlledObject.BeginShoot(MyShootActionEnum.PrimaryAction);
                            }
                        }

                        if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED))
                        {
                            controlledObject.EndShoot(MyShootActionEnum.PrimaryAction);
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SECONDARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
                        {
                            controlledObject.BeginShoot(MyShootActionEnum.SecondaryAction);
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SECONDARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED))
                        {
                            controlledObject.EndShoot(MyShootActionEnum.SecondaryAction);
                        }
                    }

                    if (context == MySpaceBindingCreator.CX_CHARACTER || context == MySpaceBindingCreator.CX_SPACESHIP)
                    {
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.USE, MyControlStateType.NEW_PRESSED))
                        {
                            // Key press
                            if (currentCameraController != null)
                            {
                                if (!currentCameraController.HandleUse())
                                {
                                    controlledObject.Use();
                                }
                            }
                            else
                            {
                                controlledObject.Use();
                            }
                        }
                        else if (MyControllerHelper.IsControl(context, MyControlsSpace.USE, MyControlStateType.PRESSED))
                        {
                            // Key not pressed this frame, holding from previous
                            controlledObject.UseContinues();
                        }
                        else if (MyControllerHelper.IsControl(context, MyControlsSpace.USE, MyControlStateType.NEW_RELEASED))
                        {
                            controlledObject.UseFinished();
                        }

                        //Temp fix until spectators are implemented as entities
                        //Prevents controlled object from getting input while spectator mode is enabled
                        if (!(MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.UserControlled))
                        {
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.CROUCH, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.Crouch();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.CROUCH, MyControlStateType.PRESSED))
                            {
                                controlledObject.Down();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.SPRINT, MyControlStateType.PRESSED))
                            {
                                controlledObject.Sprint();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.JUMP, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.Jump();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.JUMP, MyControlStateType.PRESSED))
                            {
                                controlledObject.Up();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.SWITCH_WALK, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.SwitchWalk();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.BROADCASTING, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.SwitchBroadcasting();
                            }
                            if (MyControllerHelper.IsControl(context, MyControlsSpace.HELMET, MyControlStateType.NEW_PRESSED))
                            {
                                controlledObject.SwitchHelmet();
                            }
                        }

                        if (MyControllerHelper.IsControl(context, MyControlsSpace.DAMPING, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchDamping();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.THRUSTS, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchThrusts();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.HEADLIGHTS, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchLights();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.TOGGLE_REACTORS, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchReactors();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.LANDING_GEAR, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                            controlledObject.SwitchLeadingGears();
                        }
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SUICIDE, MyControlStateType.NEW_PRESSED))
                        {
                            controlledObject.Die();
                        }
                        if ((controlledObject as MyCockpit) != null && MyControllerHelper.IsControl(context, MyControlsSpace.CUBE_COLOR_CHANGE, MyControlStateType.NEW_PRESSED))
                        {
                            (controlledObject as MyCockpit).SwitchWeaponMode();
                        }
                    }
                }
                if (MyControllerHelper.IsControl(context, MyControlsSpace.TERMINAL, MyControlStateType.NEW_PRESSED) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    controlledObject.ShowTerminal();
                }

                if (MyControllerHelper.IsControl(context, MyControlsSpace.INVENTORY, MyControlStateType.NEW_PRESSED) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    controlledObject.ShowInventory();
                }

                if (MyControllerHelper.IsControl(context, MyControlsSpace.CONTROL_MENU, MyControlStateType.NEW_PRESSED) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    m_controlMenu.OpenControlMenu(controlledObject);
                }

                if (!MyCompilationSymbols.RenderProfiling && MyControllerHelper.IsControl(context, MyControlsSpace.CHAT_SCREEN, MyControlStateType.NEW_PRESSED))
                {
                    if (MyGuiScreenChat.Static == null)
                    {
                        Vector2 chatPos = new Vector2(0.01f, 0.84f);
                        chatPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref chatPos);
                        MyGuiScreenChat chatScreen = new MyGuiScreenChat(chatPos);
                        MyGuiSandbox.AddScreen(chatScreen);
                    }
                }

                if (MyPerGameSettings.VoiceChatEnabled)
                {
                    if (MyControllerHelper.IsControl(context, MyControlsSpace.VOICE_CHAT, MyControlStateType.NEW_PRESSED))
                    {
                        MyVoiceChatSessionComponent.Static.StartRecording();
                    }
                    //else if (MyControllerHelper.IsControl(context, MyControlsSpace.VOICE_CHAT, MyControlStateType.NEW_RELEASED))
                    // TODO: If other key was pressed during VOIP, NEW_RELEASED will return false even if this key was pressed, is this correct? We don't store key states?
                    else if (MyVoiceChatSessionComponent.Static.IsRecording && !MyControllerHelper.IsControl(context, MyControlsSpace.VOICE_CHAT, MyControlStateType.PRESSED))
                    {
                        MyVoiceChatSessionComponent.Static.StopRecording();
                    }
                }
            }

            MoveAndRotatePlayerOrCamera();

            // Quick save or quick load.
            if (MyInput.Static.IsNewKeyPressed(MyKeys.F5))
            {
                if (!MySession.Static.IsScenario)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    var currentSession = MySession.Static.CurrentPath;

                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        if (MySession.Static.ClientCanSave || Sync.IsServer)
                        {
                            if (!MyAsyncSaving.InProgress)
                            {
                                var messageBox = MyGuiSandbox.CreateMessageBox(
                                    buttonType : MyMessageBoxButtonsType.YES_NO,
                                    messageText : MyTexts.Get(MySpaceTexts.MessageBoxTextAreYouSureYouWantToQuickSave),
                                    messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionPleaseConfirm),
                                    callback : delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
                                {
                                    if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                                    {
                                        MyAsyncSaving.Start(() => MySector.ResetEyeAdaptation = true);    //black screen after save
                                    }
                                });
                                messageBox.SkipTransition      = true;
                                messageBox.CloseBeforeCallback = true;
                                MyGuiSandbox.AddScreen(messageBox);
                            }
                        }
                        else
                        {
                            MyHud.Notifications.Add(MyNotificationSingletons.ClientCannotSave);
                        }
                    }
                    else if (Sync.IsServer)
                    {
                        ShowLoadMessageBox(currentSession);
                    }
                    else
                    {
                        // Is multiplayer client, reconnect
                        ShowReconnectMessageBox();
                    }
                }
            }

            //  Launch main menu
            if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape) ||
                MyControllerHelper.IsControl(context, MyControlsGUI.MAIN_MENU, MyControlStateType.NEW_PRESSED))
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);

                //Allow changing video options from game in DX version
                MyGuiScreenMainMenu.AddMainMenu();
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.F3))
            {
                if (Sync.MultiplayerActive)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    MyGuiSandbox.AddScreen(new MyGuiScreenPlayers());
                }
                else
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.MultiplayerDisabled);
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.BUILD_SCREEN) && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
            {
                if (MyGuiScreenCubeBuilder.Static == null && (MySession.ControlledEntity is MyShipController || MySession.ControlledEntity is MyCharacter))
                {
                    int offset = 0;
                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        offset += 6;
                    }
                    if (MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        offset += 12;
                    }
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    MyGuiSandbox.AddScreen(
                        MyGuiScreenGamePlay.ActiveGameplayScreen = MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.ToolbarConfigScreen,
                                                                                             offset,
                                                                                             MySession.ControlledEntity as MyShipController)
                        );
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.PAUSE_GAME))
            {
                MySandboxGame.UserPauseToggle();
            }

            if (MySession.Static != null)
            {
                if (MyInput.Static.IsNewKeyPressed(MyKeys.F10))
                {
                    if (MyPerGameSettings.GUI.VoxelMapEditingScreen != null && MySession.Static.CreativeMode && MyInput.Static.IsAnyShiftKeyPressed())
                    { // Shift+F10
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.VoxelMapEditingScreen));
                    }
                    else
                    { // F10
                        if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle)
                        {
                            if (MyPerGameSettings.GUI.BattleBlueprintScreen != null)
                            {
                                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.BattleBlueprintScreen));
                            }
                            else
                            {
                                Debug.Fail("No battle blueprint screen");
                            }
                        }
                        else
                        {
                            MyGuiSandbox.AddScreen(new MyGuiBlueprintScreen(MyCubeBuilder.Static.Clipboard));
                        }
                    }
                }
            }

            // F11, mod debug
            if (MyInput.Static.IsNewKeyPressed(MyKeys.F11) && !MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed())
            {
                MyDX9Gui.SwitchModDebugScreen();
            }
        }
Exemplo n.º 16
0
        private void DrawGravityIndicator(MyHudGravityIndicator indicator, MyHudCharacterInfo characterInfo)
        {
            if (indicator.Entity == null)
            {
                return;
            }

            Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator ? indicator.Entity.PositionComp.WorldAABB.Center : MySpectatorCameraController.Static.Position);
            //gravity += MyPhysics.HavokWorld.Gravity;
            bool anyGravity = !MyUtils.IsZero(gravity.Length());

            // Background and text drawing
            MyFontEnum    font;
            StringBuilder text;

            m_hudIndicatorText.Clear();
            m_hudIndicatorText.AppendFormatedDecimal("", gravity.Length() / 9.81f, 1, " g");
            MyGuiPaddedTexture bg;

            if (anyGravity)
            {
                font = MyFontEnum.Blue;
                text = MyTexts.Get(MySpaceTexts.HudInfoGravity);
                bg   = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            }
            else
            {
                font = MyFontEnum.Red;
                text = MyTexts.Get(MySpaceTexts.HudInfoNoGravity);
                bg   = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_RED;
            }

            bool    drawOxygen  = MySession.Static.Settings.EnableOxygen;
            Vector2 bgSizeDelta = new Vector2(0.015f, 0f);
            float   oxygenLevel = 0f;

            Vector2 bgSize = bg.SizeGui + bgSizeDelta;

            Vector2            bgPos, textPos, gTextPos, position;
            MyGuiDrawAlignEnum align;

            if (indicator.Entity is MyCharacter)
            {
                bgPos    = new Vector2(0.99f, 0.99f);
                bgPos    = ConvertHudToNormalizedGuiPosition(ref bgPos);
                textPos  = bgPos - bgSize * new Vector2(0.94f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                gTextPos = bgPos - bgSize * new Vector2(0.56f, 0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                align    = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                position = bgPos - bgSize * new Vector2(0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f;

                oxygenLevel = (indicator.Entity as MyCharacter).EnvironmentOxygenLevel;
            }
            else
            {
                bgPos    = new Vector2(0.01f, 1f - (characterInfo.Data.GetGuiHeight() + 0.02f));
                bgPos    = ConvertHudToNormalizedGuiPosition(ref bgPos);
                textPos  = bgPos + bgSize * new Vector2(1 - 0.94f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                gTextPos = bgPos + bgSize * new Vector2(1 - 0.56f, -0.98f) + bg.PaddingSizeGui * Vector2.UnitY * 0.2f;
                align    = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                position = bgPos - bgSize * new Vector2(-0.5f, 0.5f) + bg.PaddingSizeGui * Vector2.UnitY * 0.5f;

                var cockpit = indicator.Entity as MyCockpit;
                if (cockpit != null && cockpit.Pilot != null)
                {
                    oxygenLevel = cockpit.Pilot.EnvironmentOxygenLevel;
                }
                else
                {
                    drawOxygen = false;
                }
            }

            if (drawOxygen)
            {
                bgSizeDelta += new Vector2(0f, 0.025f);
            }

            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, bg.SizeGui + bgSizeDelta, Color.White, align);

            MyGuiManager.DrawString(font, text, textPos, m_textScale);

            if (drawOxygen)
            {
                var oxygenFont = MyFontEnum.Blue;
                var oxygenText = new StringBuilder("Oxygen: ");
                if (oxygenLevel == 0f)
                {
                    oxygenText.Append("None");
                    oxygenFont = MyFontEnum.Red;
                }
                else if (oxygenLevel < 0.5f)
                {
                    oxygenText.Append("Low");
                    oxygenFont = MyFontEnum.Red;
                }
                else
                {
                    oxygenText.Append("High");
                }

                MyGuiManager.DrawString(oxygenFont, oxygenText, textPos - new Vector2(0f, 0.025f), m_textScale);
            }

            if (anyGravity)
            {
                MyGuiManager.DrawString(MyFontEnum.White, m_hudIndicatorText, gTextPos, m_textScale);
            }

            position = MyGuiManager.GetHudSize() * ConvertNormalizedGuiToHud(ref position);
            if (MyVideoSettingsManager.IsTripleHead())
            {
                position.X += 1.0f;
            }

            // Draw each of gravity indicators.
            foreach (var generatorGravity in MyGravityProviderSystem.GravityVectors)
            {
                DrawGravityVectorIndicator(position, generatorGravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);
            }

            //if (MyPhysics.HavokWorld.Gravity != Vector3.Zero)
            //    DrawGravityVectorIndicator(position, MyPhysics.HavokWorld.Gravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);

            if (anyGravity)
            {
                DrawGravityVectorIndicator(position, gravity, MyHudTexturesEnum.gravity_arrow, Color.White);
            }

            // Draw center
            MyAtlasTextureCoordinate centerTextCoord;

            if (anyGravity)
            {
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_white);
            }
            else
            {
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_red);
            }

            float   hudSizeX    = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float   hudSizeY    = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            Vector2 rightVector = Vector2.UnitX;

            MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                position,
                centerTextCoord.Offset,
                centerTextCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                MyHudConstants.HUD_COLOR_LIGHT,
                Vector2.One * 0.005f);
        }
        public override void HandleInput()
        {
            if (!m_isActive)
            {
                return;
            }
            if (!(MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay))
            {
                return;
            }

            if (!
                (VRage.Input.MyInput.Static.ENABLE_DEVELOPER_KEYS || !MySession.Static.SurvivalMode || (MyMultiplayer.Static != null && MyMultiplayer.Static.IsAdmin(MySession.LocalHumanPlayer.Id.SteamId)))
                )
            {
                return;
            }


            base.HandleInput();

            if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
            {
                m_startTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            }

            if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED))
            {
                var gridBuilders = MyPrefabManager.Static.GetGridPrefab(CurrentDefinition.PrefabToThrow);

                Vector3D cameraPos = Vector3D.Zero;
                Vector3D cameraDir = Vector3D.Zero;

                if (USE_SPECTATOR_FOR_THROW)
                {
                    cameraPos = MySpectator.Static.Position;
                    cameraDir = MySpectator.Static.Orientation.Forward;
                }
                else
                {
                    if (MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.ThirdPersonSpectator || MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.Entity)
                    {
                        if (MySession.ControlledEntity == null)
                        {
                            return;
                        }

                        cameraPos = MySession.ControlledEntity.GetHeadMatrix(true, true).Translation;
                        cameraDir = MySession.ControlledEntity.GetHeadMatrix(true, true).Forward;
                    }
                    else
                    {
                        cameraPos = MySector.MainCamera.Position;
                        cameraDir = MySector.MainCamera.WorldMatrix.Forward;
                    }
                }

                var position = cameraPos + cameraDir;

                float deltaSeconds = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_startTime) / 1000.0f;
                float velocity     = deltaSeconds / CurrentDefinition.PushTime * CurrentDefinition.MaxSpeed;
                velocity = MathHelper.Clamp(velocity, CurrentDefinition.MinSpeed, CurrentDefinition.MaxSpeed);
                var   linearVelocity = cameraDir * velocity;
                float mass           = 0;
                if (CurrentDefinition.Mass.HasValue)
                {
                    mass = Sandbox.Engine.Physics.MyDestructionHelper.MassToHavok(CurrentDefinition.Mass.Value);
                }

                gridBuilders[0].EntityId = MyEntityIdentifier.AllocateId();
                MySyncThrower.RequestThrow(gridBuilders[0], position, linearVelocity, mass, CurrentDefinition.ThrowSound);

                m_startTime = 0;
            }
        }
Exemplo n.º 18
0
        private void PlaceAreaMarker()
        {
            Vector3D cameraPos, cameraDir;

            if (MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.ThirdPersonSpectator || MySession.GetCameraControllerEnum() == Common.ObjectBuilders.MyCameraControllerEnum.Entity)
            {
                var headMatrix = MySession.ControlledEntity.GetHeadMatrix(true, true);
                cameraPos = headMatrix.Translation;
                cameraDir = headMatrix.Forward;
            }
            else
            {
                cameraPos = MySector.MainCamera.Position;
                cameraDir = MySector.MainCamera.WorldMatrix.Forward;
            }

            List <MyPhysics.HitInfo> hitInfos = new List <MyPhysics.HitInfo>();

            MyPhysics.CastRay(cameraPos, cameraPos + cameraDir * 100, hitInfos, MyPhysics.ObjectDetectionCollisionLayer);
            if (hitInfos.Count == 0)
            {
                return;
            }

            MyPhysics.HitInfo?closestValidHit = null;
            foreach (var hitInfo in hitInfos)
            {
                var ent = hitInfo.HkHitInfo.Body.GetEntity();
                if (ent is MyCubeGrid)
                {
                    closestValidHit = hitInfo;
                    break;
                }
                else if (ent is MyVoxelMap)
                {
                    closestValidHit = hitInfo;
                    break;
                }
            }

            if (closestValidHit.HasValue)
            {
                MyAreaMarkerDefinition definition = AreaMarkerDefinition;
                Debug.Assert(definition != null, "Area marker definition cannot be null!");
                if (definition == null)
                {
                    return;
                }

                Vector3D position = closestValidHit.Value.Position;

                var forward = Vector3D.Reject(cameraDir, Vector3D.Up);

                if (Vector3D.IsZero(forward))
                {
                    forward = Vector3D.Forward;
                }

                var positionAndOrientation = new MyPositionAndOrientation(position, Vector3D.Normalize(forward), Vector3D.Up);

                MyObjectBuilder_AreaMarker objectBuilder = (MyObjectBuilder_AreaMarker)MyObjectBuilderSerializer.CreateNewObject(definition.Id);
                objectBuilder.PersistentFlags        = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene;
                objectBuilder.PositionAndOrientation = positionAndOrientation;

                if (objectBuilder.IsSynced)
                {
                    MySyncCreate.RequestEntityCreate(objectBuilder);
                }
                else
                {
                    MyAreaMarker flag = MyEntityFactory.CreateEntity <MyAreaMarker>(objectBuilder);
                    flag.Init(objectBuilder);

                    MyEntities.Add(flag);
                }
            }
        }
Exemplo n.º 19
0
        private bool TestPlacement()
        {
            if (MySession.ControlledEntity != null &&
                (MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator))
            {
                for (int i = 0; i < m_previewVoxelMaps.Count; ++i)
                {
                    var aabb = m_previewVoxelMaps[i].PositionComp.WorldAABB;

                    using (m_tmpResultList.GetClearToken())
                    {
                        MyGamePruningStructure.GetAllEntitiesInBox(ref aabb, m_tmpResultList);

                        foreach (var entity in m_tmpResultList)
                        {
                            m_tmpResultHashset.Add(entity.GetTopMostParent());
                        }

                        foreach (var entity in m_tmpResultHashset)
                        {
                            //ignore asteroids
                            if (entity is MyVoxelBase)
                            {
                                continue;
                            }

                            //ignore stations
                            if (entity is MyCubeGrid)
                            {
                                var grid = entity as MyCubeGrid;
                                if (grid.IsStatic)
                                {
                                    continue;
                                }
                            }

                            switch (m_previewVoxelMaps[i].GetVoxelRangeTypeInBoundingBox(entity.PositionComp.WorldAABB))
                            {
                            case MyVoxelRangeType.EMPTY:
                                break;

                            case MyVoxelRangeType.MIXED:
                            {
                                m_tmpResultList.Clear();
                                m_tmpResultHashset.Clear();
                                return(false);
                            }
                            break;

                            case MyVoxelRangeType.FULL:
                            {
                                m_tmpResultList.Clear();
                                m_tmpResultHashset.Clear();
                                return(false);
                            }
                            break;

                            default:
                                throw new InvalidBranchException();
                                break;
                            }
                        }
                        m_tmpResultHashset.Clear();
                    }
                }
            }
            return(true);
        }
        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();

            if (Owner != null && Owner.ControllerInfo.IsLocallyHumanControlled())
            {
                if (MySession.Static.SurvivalMode && (MySession.GetCameraControllerEnum() != MyCameraControllerEnum.Spectator || MyFinalBuildConstants.IS_OFFICIAL))
                {
                    var character = ((MyCharacter)this.CharacterInventory.Owner);
                    MyCubeBuilder.Static.MaxGridDistanceFrom = character.PositionComp.GetPosition() + character.WorldMatrix.Up * 1.8f;
                }
                else
                {
                    MyCubeBuilder.Static.MaxGridDistanceFrom = null;
                }
            }

            //MyTrace.Watch("MyEngineerToolBase.RequiredPowerInput", RequiredPowerInput);
        }
Exemplo n.º 21
0
        //  Sends input (keyboard/mouse) to screen which has focus (top-most)
        public void HandleInputAfterSimulation()
        {
            bool cameraControllerMovementAllowed = MyScreenManager.GetScreenWithFocus() == MyGuiScreenGamePlay.Static && MyGuiScreenGamePlay.Static != null && !MyScreenManager.InputToNonFocusedScreens;
            bool lookAroundEnabled = MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND) || (MySession.ControlledEntity != null && MySession.ControlledEntity.PrimaryLookaround);

            //After respawn, the controlled object might be null
            bool shouldStopControlledObject = MySession.ControlledEntity != null && (!cameraControllerMovementAllowed && m_cameraControllerMovementAllowed != cameraControllerMovementAllowed);

            if (MySession.Static != null)
            {
                bool movementAllowedInPause = MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Spectator ||
                                              MySession.GetCameraControllerEnum() == MyCameraControllerEnum.SpectatorDelta ||
                                              MySession.GetCameraControllerEnum() == MyCameraControllerEnum.SpectatorFixed;
                bool rotationAllowedInPause = movementAllowedInPause || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator;
                bool devScreenFlag          = MyScreenManager.GetScreenWithFocus() is MyGuiScreenDebugBase && !MyInput.Static.IsAnyAltKeyPressed();
                MyCameraControllerEnum cce  = MySession.GetCameraControllerEnum();

                float             rollIndicator     = MyInput.Static.GetRoll();
                Vector2           rotationIndicator = MyInput.Static.GetRotation();
                VRageMath.Vector3 moveIndicator     = MyInput.Static.GetPositionDelta();

                if (MySandboxGame.IsPaused)
                {
                    if (!movementAllowedInPause && !rotationAllowedInPause)
                    {
                        return;
                    }

                    if (!movementAllowedInPause)
                    {
                        moveIndicator = VRageMath.Vector3.Zero;
                    }
                    if (!rotationAllowedInPause || devScreenFlag)
                    {
                        rollIndicator     = 0.0f;
                        rotationIndicator = Vector2.Zero;
                    }

                    MySession.Static.CameraController.Rotate(rotationIndicator, rollIndicator);
                }
                else if (lookAroundEnabled)
                {
                    if (cameraControllerMovementAllowed)
                    {
                        //Then move camera (because it can be dependent on control object)
                        MySession.Static.CameraController.Rotate(rotationIndicator, rollIndicator);

                        if (!m_lookAroundEnabled && shouldStopControlledObject)
                        {
                            MySession.ControlledEntity.MoveAndRotateStopped();
                        }
                    }

                    if (shouldStopControlledObject)
                    {
                        MySession.Static.CameraController.RotateStopped();
                    }
                }
                //Hack to make spectators work until they are made entities
                else if (MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.ConstantDelta)
                {
                    if (cameraControllerMovementAllowed)
                    {
                        MySpectatorCameraController.Static.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                    }
                }

                if (shouldStopControlledObject)
                {
                    MySession.ControlledEntity.MoveAndRotateStopped();
                }
            }

            m_cameraControllerMovementAllowed = cameraControllerMovementAllowed;
            m_lookAroundEnabled = lookAroundEnabled;
        }