예제 #1
0
        public override void UpdateOnceBeforeFrame()
        {
            if (firstrun)
            {
                var info = new List <MyUpgradeModuleInfo>();
                hyperDriveBlock.GetUpgradeList(out info);

                Maxhyper = info.FirstOrDefault(x => x.UpgradeType == "WarpFactor").Modifier;

                ResourceSink.SetMaxRequiredInputByType(_electricity, HyperFunctions.MinimumPowertoActivate());
                ResourceSink.SetRequiredInputByType(_electricity, HyperFunctions.PowerConsumption());
                ResourceSink.SetRequiredInputFuncByType(_electricity, HyperFunctions.PowerConsumption);
                ResourceSink.Update();

                hyperDriveBlock.AppendingCustomInfo += HyperFunctions.hyperDriveBlock_AppendingCustomInfo;

                Maxhyper = Maxhyper * 100f;
                emitter  = new Sandbox.Game.Entities.MyEntity3DSoundEmitter(hyperDriveBlock as MyEntity);
                MyEntity3DSoundEmitter.PreloadSound(pair);
                HyperFunctions.CreatehyperUI();

                firstrun = false;

                White = Color.White;
                MyVisualScriptLogicProvider.ScreenColorFadingSetColor(White);
            }
        }
예제 #2
0
 public override void UpdateOnceBeforeFrame()
 {
     if (firstrun)
     {
         HyperFunctions.Init();
     }
 }
예제 #3
0
        public override void UpdateBeforeSimulation()
        {
            // Ignore damaged or build progress hyper_blocks. Ignore ghost grids (projections).
            if (!hyperDriveBlock.IsFunctional || hyperDriveBlock.CubeGrid.Physics == null)
            {
                return;
            }
            _ticks++;
            _tick++;
            HyperFunctions.UpdateGridPower();
            ResourceSink.Update();
            hyperDriveBlock.RefreshCustomInfo();

            if (!firstrun)
            {
                if (_ticks > 12)
                {
                    HyperFunctions.RefreshLists();
                    HyperFunctions.Distance();
                    totalMass  = Math.Sqrt(hyperDriveBlock.CubeGrid.Physics.Mass);
                    totalMassF = (float)totalMass;
                    HyperFunctions.curPDistF = (float)HyperFunctions.distance;
                    MyAPIGateway.Parallel.StartBackground(HyperFunctions.BackGroundChecks);
                    HyperFunctions._powerPercent = (HyperFunctions._maxPower * 0.6f);

                    if (HyperFunctions.curPDistF < HyperFunctions.maxPDistF)
                    {
                        if (HyperFunctions._powerPercent >= 100f && HyperFunctions._powerPercent <= Maxhyper)
                        {
                            hyperFactor = HyperFunctions._powerPercent;
                            float invSqr = (((HyperFunctions.maxPDistF * HyperFunctions.maxPDistF) / (HyperFunctions.curPDistF * HyperFunctions.curPDistF)) * 0.01f);
                            if (invSqr < 0.95f)
                            {
                                hyperFactor = (hyperFactor - (hyperFactor * invSqr));
                                gravMsg     = true;
                            }
                            else if (invSqr >= 0.95f)
                            {
                                hyperFactor = 0f;
                                Engage_OnOff();
                                if (gravMsg)
                                {
                                    var realPlayerIds = new List <long>();
                                    DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                    foreach (var id in realPlayerIds)
                                    {
                                        MyVisualScriptLogicProvider.ShowNotification("Gravity Field Interference: " + "Minimum Safe Distance - 200km", 19200, "Red", id);
                                    }
                                    gravMsg = false;
                                }
                            }
                        }
                    }
                    else if (HyperFunctions.curPDistF > HyperFunctions.maxPDistF)
                    {
                        if (HyperFunctions._powerPercent >= 100f && HyperFunctions._powerPercent <= Maxhyper)
                        {
                            hyperFactor = HyperFunctions._powerPercent;
                        }
                    }

                    //Convert Mass Double to non-Infinite Float//
                    if (float.IsPositiveInfinity(totalMassF))
                    {
                        totalMassF = float.MaxValue;
                    }
                    else if (float.IsNegativeInfinity(totalMassF))
                    {
                        totalMassF = float.MinValue;
                    }
                    if (float.IsPositiveInfinity(HyperFunctions.curPDistF))
                    {
                        HyperFunctions.curPDistF = float.MaxValue;
                    }
                    else if (float.IsNegativeInfinity(HyperFunctions.curPDistF))
                    {
                        HyperFunctions.curPDistF = float.MinValue;
                    }

                    _ticks = 0;
                }
                if (MyAPIGateway.Session.IsServer)
                {
                    if (ResourceSink.IsPowerAvailable(_electricity, HyperFunctions.PowerConsumption()))
                    {
                        BubbleFormed        = true;
                        _bubbleNotification = true;
                    }
                    else if (!ResourceSink.IsPowerAvailable(_electricity, HyperFunctions.PowerConsumption()))
                    {
                        BubbleFormed = false;
                    }
                    if (_tick > 10000)
                    {
                        _tick   = 0;
                        msgSent = false;
                    }
                    if (HyperFunctions.IsWorking() && hyperDriveBlock.CubeGrid.Physics.LinearVelocity.LengthSquared() >= 0f && HyperEngaged)
                    {
                        hyper = true;
                        var grid = hyperDriveBlock.CubeGrid;
                        //_minSpeed = hyperDriveBlock.CubeGrid.Physics.LinearVelocity.LengthSquared();

                        //if (_minSpeed >= 5000)
                        //{
                        if (BubbleFormed && hyperDriveBlock.CubeGrid.Physics != null && hyperDriveBlock.CubeGrid.WorldMatrix != null && hyperDriveBlock.CubeGrid.WorldMatrix.Translation != null && warpTimer < 300)
                        {
                            //remoteControl;


                            //hyperDriveBlock.SetLocalMatrix(hyperDriveBlock.LocalMatrix, shipForward);

                            //hyperDriveBlock.CubeGrid.SetLocalMatrix(hyperDriveBlock.CubeGrid.LocalMatrix, hyperDriveBlock.Orientation.Forward);
                            //var fwd = hyperDriveBlock.CubeGrid.LocalMatrix.GetDirectionVector(hyperDriveBlock.Orientation.Forward);

                            from = hyperDriveBlock.WorldMatrix.Translation + hyperDriveBlock.WorldMatrix.Forward;    // * 1d;
                            to   = hyperDriveBlock.WorldMatrix.Translation + hyperDriveBlock.WorldMatrix.Forward * 50d;

                            var gridSpeed       = hyperDriveBlock.CubeGrid.WorldMatrix;
                            var gridTranslation = hyperDriveBlock.CubeGrid.WorldMatrix.Translation;
                            var gPhysics        = hyperDriveBlock.CubeGrid.Physics;
                            var gameSteps       = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
                            var predictedMatrix = hyperDriveBlock.CubeGrid.WorldMatrix;
                            var multipler       = 500;
                            predictedMatrix.Translation = gridTranslation + gPhysics.GetVelocityAtPoint(gridTranslation) * gameSteps * multipler;
                            //gPhysics.LinearVelocity = (fwd );
                            gPhysics.LinearVelocity = from - to;

                            //object not set remoteControl.DampenersOverride = false;
                            //grid.Physics.SetSpeeds(gPhysics.LinearVelocity, Vector3.Zero);
                            gPhysics.AngularVelocity = Vector3D.Zero;
                            grid.Teleport(predictedMatrix);
                            gPhysics.AngularVelocity = Vector3D.Zero;
                            warpTimer = (warpTimer + 1);

                            if (warpTimer > 250 && fade)
                            {
                                fade = false;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    //MyVisualScriptLogicProvider.ShowNotification("Jump Initialisation Success: " + "Maybe", 19200, "White", id);
                                    MyVisualScriptLogicProvider.ScreenColorFadingStart(0.25f, true);
                                }
                            }



                            //var setSpeed = hyperDriveBlock.CubeGrid.Physics.LinearVelocity;
                            //remoteControl.WorldMatrix.SetDirectionVector(remoteControl.Orientation.Forward, shipForward);


                            /* Original Code
                             * var gridSpeed = hyperDriveBlock.CubeGrid.WorldMatrix;
                             * var gridTranslation = hyperDriveBlock.CubeGrid.WorldMatrix.Translation;
                             * var gPhysics = hyperDriveBlock.CubeGrid.Physics;
                             * var gameSteps = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
                             * var predictedMatrix = hyperDriveBlock.CubeGrid.WorldMatrix;
                             * var multipler = WF_Scale;
                             * predictedMatrix.Translation = gridTranslation + gPhysics.GetVelocityAtPoint(gridTranslation) * gameSteps * multipler;
                             * gPhysics.AngularVelocity = Vector3D.Zero;
                             * grid.Teleport(predictedMatrix);
                             * gPhysics.AngularVelocity = Vector3D.Zero;*/
                        }
                        //}
                        else
                        {
                            hyper     = false;
                            warpTimer = 0;
                            fade      = true;
                            var realPlayerIds = new List <long>();
                            DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                            foreach (var id in realPlayerIds)
                            {
                                MyVisualScriptLogicProvider.ShowNotification("Jump Time: " + "Time to Jump to HyperSpace", 19200, "Red", id);
                                MyVisualScriptLogicProvider.ScreenColorFadingStartSwitch(0.1f);
                            }

                            //Color White = new Color();
                            //White = Color.White;
                            //MyVisualScriptLogicProvider.ScreenColorFadingSetColor(White);
                            //MyVisualScriptLogicProvider.ScreenColorFadingStart(4, true);
                            //MyVisualScriptLogicProvider.ScreenColorFadingStartSwitch(1);
                        }
                    }
                    if (!BubbleFormed && hyperDriveBlock.Enabled && _tick > 16)
                    {
                        var realPlayerIds = new List <long>();
                        DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                        foreach (var id in realPlayerIds)
                        {
                            MyVisualScriptLogicProvider.ShowNotification("hyper Field Collapse Imminent: " + "Emergency Shutdown" + "\nInsufficient Power - You require additional pylons.", 19200, "Red", id);
                        }
                        WF_Scale = 0f;
                        hyper    = false;
                        hyperDriveBlock.Enabled = false;
                    }
                    if (!HyperFunctions.IsWorking() && hyper)
                    {
                        var realPlayerIds = new List <long>();
                        DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                        foreach (var id in realPlayerIds)
                        {
                            MyVisualScriptLogicProvider.ShowNotification("hyper Drive Manually Disabled: Emergency Stop", 19200, "White", id);
                        }
                        WF_Scale = 0f;
                        hyper    = false;
                        HyperFunctions.EmergencyStop();
                    }

                    if (hyper)
                    {
                        if (WF_Scale < hyperFactor && WF_Scale >= 0f)
                        {
                            float WF_CurveM = (hyperFactor - hyperFactor * 0.05f);
                            if (WF_Scale < WF_CurveM)
                            {
                                WF_Curve = (hyperFactor * 0.0001f);
                                WF_Scale = (WF_Curve + (WF_Scale + (WF_Scale * 0.0025f)));
                            }
                            else if (WF_Scale > WF_CurveM)
                            {
                                WF_Scale = hyperFactor;
                            }
                        }
                        else if (WF_Scale > hyperFactor && WF_Scale >= 0f)
                        {
                            float WF_CurveP = (hyperFactor * 0.05f + hyperFactor);
                            if (WF_Scale > WF_CurveP)
                            {
                                WF_Scale--;
                            }
                            if (WF_Scale < WF_CurveP)
                            {
                                WF_Scale = hyperFactor;
                            }
                        }
                        else if (WF_Scale == hyperFactor && WF_Scale > 0.1f)
                        {
                            if (hyperFactor > 30f && hyper && !msgSent)
                            {
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);

                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ShowNotification("Target hyper Achieved", 19200, "White", id);
                                    msgSent = true;
                                }
                            }
                        }
                        else if (WF_Scale < 0f)
                        {
                            hyperFactor = (hyperFactor * -1f);
                            WF_Scale    = hyperFactor;
                            hyper       = false;
                        }
                    }
                    if (!hyper)
                    {
                        emitter.StopSound(false, true);
                        if (WF_Scale <= 0f)
                        {
                            hyperFactor  = 0f;
                            WF_Scale     = hyperFactor;
                            HyperEngaged = false;
                        }
                        else if (WF_Scale > 0f)
                        {
                            hyperFactor  = 0f;
                            WF_Scale     = hyperFactor;
                            HyperEngaged = false;
                        }
                    }
                }
            }
        }
예제 #4
0
        public override void UpdateBeforeSimulation()
        {
            // Ignore damaged or build progress hyper_blocks. Ignore ghost grids (projections).
            if (!hyperDriveBlock.IsFunctional || hyperDriveBlock.CubeGrid.Physics == null)
            {
                return;
            }
            _ticks++;
            _tick++;
            if (!firstrun)
            {
                if (_ticks > 12)
                {
                    MyAPIGateway.Parallel.StartBackground(HyperFunctions.BackGroundChecks);
                    //HyperFunctions._powerPercent = (HyperFunctions._maxPower * 0.6f);
                    HyperFunctions.UpdateGridPower();
                    HyperFunctions.ResourceSink.Update();
                    hyperDriveBlock.RefreshCustomInfo();
                    _ticks = 0;
                }
                if (MyAPIGateway.Session.IsServer)
                {
                    if (!_shellBool)
                    {
                        try
                        {
                            var parent = (MyEntity)hyperDriveBlock.CubeGrid;
                            Spawn._emptyGridShell = Spawn.EmptyEntity("dShellPassive2", $"{Session.Instance.ModPath()}{Spawn._modelShell}", parent, true);
                            Spawn._emptyGridShell.Render.CastShadows = false;
                            Spawn._emptyGridShell.IsPreview          = true;
                            Spawn._emptyGridShell.Render.Visible     = true;
                            Spawn._emptyGridShell.Render.RemoveRenderObjects();
                            Spawn._emptyGridShell.Render.UpdateRenderObject(true);
                            Spawn._emptyGridShell.Render.UpdateRenderObject(false);
                            Spawn._emptyGridShell.Save     = false;
                            Spawn._emptyGridShell.SyncFlag = false;
                            try
                            {
                                Session.Instance.CreateMobileShape();
                                Spawn._emptyGridShell.PositionComp.LocalMatrix = Matrix.Zero;  // Bug - Cannot just change X coord, so I reset first.
                                Spawn._emptyGridShell.PositionComp.LocalMatrix = Spawn._shieldShapeMatrix;
                            }
                            catch
                            {
                                Logging.Logging.Instance.WriteLine("CreateMobileShape() Failure");
                            }
                        }
                        catch
                        {
                            Logging.Logging.Instance.WriteLine("emptyGrid Failure");
                        }

                        _shellBool = true;
                    }
                    if (HyperFunctions.ResourceSink.IsPowerAvailable(HyperFunctions._electricity, HyperFunctions.PowerConsumption()))
                    {
                        BubbleFormed        = true;
                        _bubbleNotification = true;
                    }
                    else if (!HyperFunctions.ResourceSink.IsPowerAvailable(HyperFunctions._electricity, HyperFunctions.PowerConsumption()))
                    {
                        BubbleFormed = false;
                    }
                    if (_tick > 10000)
                    {
                        _tick   = 0;
                        msgSent = false;
                    }
                    if (HyperFunctions.IsWorking() && HyperEngaged)
                    {
                        hyper = true;
                        //var grid = hyperDriveBlock.CubeGrid;
                        if (BubbleFormed && hyperDriveBlock.CubeGrid.Physics != null && hyperDriveBlock.CubeGrid.WorldMatrix != null && hyperDriveBlock.CubeGrid.WorldMatrix.Translation != null && warpTimer < 120)
                        {
                            HyperFunctions.Warp();
                            warpTimer = (warpTimer + 1);

                            if (warpTimer > 95 && fade)
                            {
                                fade = false;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    //MyVisualScriptLogicProvider.ShowNotification("Jump Initialisation Success: " + "Maybe", 9500, "White", id);
                                    MyVisualScriptLogicProvider.ScreenColorFadingStart(0.25f, true);
                                }
                                lastPos         = hyperDriveBlock.CubeGrid.GetPosition();
                                from            = hyperDriveBlock.WorldMatrix.Translation + hyperDriveBlock.WorldMatrix.Forward;// * 1d;
                                to              = hyperDriveBlock.WorldMatrix.Translation + hyperDriveBlock.WorldMatrix.Forward * 2001d;
                                destination     = from - to;
                                hyperSpaceTimer = 7200;
                                //hyperSpaceTimer = (hyperSpaceTimer + distanceVar);
                                jumpOut = true;
                                HyperFunctions.HyperJump();
                            }
                        }
                        else
                        {
                            hyper     = false;
                            warpTimer = 0;
                            fade      = true;
                            if (jumpOut)
                            {
                                var realPlayerIds = new List <long>();
                                jumpOut = false;
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    //MyVisualScriptLogicProvider.ShowNotification("Jump Time: " + "Time to Jump to HyperSpace", 9500, "White", id);
                                    MyVisualScriptLogicProvider.ScreenColorFadingStartSwitch(0.25f);
                                }
                                hyperSpace   = true;
                                HyperEngaged = false;
                                HyperSpaceParticle();
                            }
                        }
                    }
                    if (hyperSpace)
                    {
                        hyperSpaceTimer = (hyperSpaceTimer - 1);

                        try
                        {
                            Session.Instance.ShellVisibility(true);
                        }
                        catch
                        {
                            Logging.Logging.Instance.WriteLine("ShellVisibility(true) Failure");
                        }

                        if (hyperSpaceTimer >= 0)
                        {
                            hyperDriveBlock.CubeGrid.Physics.AngularVelocity = Vector3D.Zero;
                            hyperDriveBlock.CubeGrid.Physics.LinearVelocity  = Vector3D.Zero;

                            if (!ExitWarning10 && hyperSpaceTimer <= 600)
                            {
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ShowNotification("10 Seconds to Normal Space", 9600, "White", id);
                                }
                                ExitWarning10 = true;
                            }
                            else if (!ExitWarning60 && hyperSpaceTimer <= 3600)
                            {
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ShowNotification("60 Seconds to Normal Space", 9600, "White", id);
                                }
                                ExitWarning60 = true;
                            }
                        }
                        else if (ExitWarning10 && ExitWarning60)
                        {
                            warpTimer = (warpTimer + 1);
                            if (warpTimer < 25 && fade)
                            {
                                fade = false;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ScreenColorFadingStart(0.25f, true);
                                }
                            }
                            else
                            {
                                HyperFunctions.HyperJumpDestination(destination, lastPos);
                                hyperSpace    = false;
                                jumpIn        = true;
                                warpTimer     = 0;
                                ExitWarning10 = false;
                                ExitWarning60 = false;
                                //hyperSpaceTimer = 7200;
                                HyperSpaceParticleStop();
                            }
                        }
                    }
                    else if (!hyperSpace && !jumpIn)
                    {
                        if (!BubbleFormed && hyperDriveBlock.Enabled && _tick > 16)
                        {
                            hyper = false;
                            hyperDriveBlock.Enabled = false;
                        }
                        if (!HyperFunctions.IsWorking() && hyper)
                        {
                            hyper = false;
                            HyperFunctions.EmergencyStop();
                        }
                        if (!hyper)
                        {
                            HyperFunctions.emitter.StopSound(false, true);
                            HyperEngaged = false;
                        }
                    }
                    if (jumpIn)
                    {
                        warpTimer = (warpTimer + 1);
                        HyperFunctions.Warp();
                        try
                        {
                            Session.Instance.ShellVisibility(false);
                        }
                        catch
                        {
                            Logging.Logging.Instance.WriteLine("ShellVisibility(false) Failure");
                        }
                        if (warpTimer > 30)
                        {
                            if (!fade)
                            {
                                fade = true;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ScreenColorFadingStartSwitch(0.04f);
                                }
                            }
                            if (warpTimer > 120)
                            {
                                warpTimer    = 0;
                                jumpIn       = false;
                                HyperEngaged = false;
                            }
                        }
                    }
                }
            }
        }