Exemplo n.º 1
0
        /// <summary>
        /// Adds thruster to thrustersInDirection
        /// </summary>
        /// <param name="thruster">The new thruster</param>
        private void newThruster(MyThrust thruster)
        {
            Log.DebugLog("thruster == null", Logger.severity.ERROR, condition: thruster == null);

            if (TP_ThrustOverride == null)
            {
                TP_ThrustOverride = thruster.GetProperty("Override") as ITerminalProperty <float>;
            }

            using (lock_thrustersInDirection.AcquireExclusiveUsing())
                m_thrustersInDirection[(int)Base6Directions.GetFlippedDirection(thruster.Orientation.Forward)].Add(thruster);
            if (TP_ThrustOverride.GetValue(thruster) != 0f)
            {
                TP_ThrustOverride.SetValue(thruster, 0f);
            }
        }
Exemplo n.º 2
0
        public static float CalculatedThrustScalar(MyThrust thruster, bool inAtmosphere, float planetaryInfluence)
        {
            float result = 1f;
            MyThrustDefinition definition = thruster.BlockDefinition;

            if (definition.NeedsAtmosphereForInfluence && !inAtmosphere)
            {
                result = definition.EffectivenessAtMinInfluence;
            }
            else if (Math.Abs(definition.MaxPlanetaryInfluence - definition.MinPlanetaryInfluence) > 0)
            {
                float value = (planetaryInfluence - definition.MinPlanetaryInfluence) * definition.InvDiffMinMaxPlanetaryInfluence;
                result = MathHelper.Lerp(definition.EffectivenessAtMinInfluence, definition.EffectivenessAtMaxInfluence, MathHelper.Clamp(value, 0f, 1f));
            }
            return(result);
        }
Exemplo n.º 3
0
        public void SetupGrid()
        {
            foreach (MyCubeBlock block in _thisGrid.GetFatBlocks())
            {
                MyThrust myThrust = block as MyThrust;
                if (myThrust != null)
                {
                    _gridSystems.ControllableThrusters.AddNewThruster(myThrust);
                    WriteToLog("SetupGrid", $"Adding Thruster {myThrust.GridThrustDirection}", LogType.General);
                    continue;
                }

                MyGyro myGyro = block as MyGyro;
                if (myGyro != null)
                {
                    _gridSystems.ControllableGyros.Add(myGyro);
                    WriteToLog("SetupGrid", $"Adding Gyro", LogType.General);
                    continue;
                }

                IMyTextSurface surface = block as IMyTextSurface;
                if (surface != null)
                {
                    if (((IMyTerminalBlock)surface).CustomData.Contains("DebugL"))
                    {
                        _gridSystems.DebugScreens.AddLeftScreen(surface);
                        _gridSystems.DebugScreens.WriteToLeft(new StringBuilder("Left Debug Screen Detected"));
                        WriteToLog("SetupGrid", $"Adding Left Debug Screen", LogType.General);
                    }

                    if (((IMyTerminalBlock)surface).CustomData.Contains("DebugR"))
                    {
                        _gridSystems.DebugScreens.AddRightScreen(surface);
                        _gridSystems.DebugScreens.WriteToRight(new StringBuilder("Right Debug Screen Detected"));
                        WriteToLog("SetupGrid", $"Adding Right Debug Screen", LogType.General);
                    }
                    continue;
                }

                IMyLandingGear gear = block as IMyLandingGear;
                if (gear == null)
                {
                    continue;
                }
                _gridSystems.ControllableLandingGear.Add(gear);
            }
        }
Exemplo n.º 4
0
            internal void <UpdateFlameAnimatorData> b__8_0(FlameData d, MyThrust t)
            {
                MatrixD localMatrix = t.PositionComp.LocalMatrix;

                d.LightPosition       = Vector3D.TransformNormal(t.Flames[0].Position, localMatrix) + localMatrix.Translation;
                d.Flames              = t.Flames;
                d.FlareSize           = t.Flares.Size;
                d.Glares              = t.Flares.SubGlares;
                d.GridScale           = t.CubeGrid.GridScale;
                d.FlareIntensity      = t.Flares.Intensity;
                d.FlamePointMaterial  = t.FlamePointMaterial;
                d.FlameLengthMaterial = t.FlameLengthMaterial;
                d.GlareQuerySize      = t.CubeGrid.GridSize / 2.5f;
                d.IdleColor           = t.BlockDefinition.FlameIdleColor;
                d.FullColor           = t.BlockDefinition.FlameFullColor;
                d.FlameLengthScale    = t.BlockDefinition.FlameLengthScale;
            }
Exemplo n.º 5
0
        private bool ApplyHeatup(MyThrust thruster, ref ThrusterBoostInfo boostInfo)
        {
            var t = (IMyThrust)thruster;

            var thrustLevel = t.CurrentThrust / t.MaxThrust;
            var heatQuant   = thrustLevel * HEAT_QUANT;

            boostInfo.CurrentHeatLevel += heatQuant;

            if (boostInfo.CurrentHeatLevel >= MAX_HEAT)
            {
                boostInfo.CurrentHeatLevel = MAX_HEAT;
                DisableBooster(thruster, ref boostInfo);
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
        private void UpdateThrusterOverheatMode(MyThrust thruster, bool enableBoost, ref ThrusterBoostInfo boostInfo)
        {
            ApplyCooldown(thruster, ref boostInfo);

            if (boostInfo.CurrentHeatLevel <= 0f)
            {
                thruster.RemoveEffect("Damage");

                if (enableBoost)
                {
                    EnableBooster(thruster, ref boostInfo);
                    boostInfo.Mode = ThrusterMode.Boost;
                }
                else
                {
                    boostInfo.Mode = ThrusterMode.Normal;
                }
            }
        }
Exemplo n.º 7
0
        private void UpdateThrusterBoostMode(MyThrust thruster, bool enableBoost, ref ThrusterBoostInfo boostInfo)
        {
            if (enableBoost)
            {
                var overheat = ApplyHeatup(thruster, ref boostInfo);
                if (overheat)
                {
                    DisableBooster(thruster, ref boostInfo);
                    boostInfo.Mode = ThrusterMode.Overheat;

                    thruster.SetEffect("Damage", true);
                }
            }
            else
            {
                DisableBooster(thruster, ref boostInfo);
                boostInfo.Mode = ThrusterMode.Normal;
            }
        }
        private static bool IsOverridden(MyThrust thrust)
        {
            var thruster = thrust as MyThrust;

            if (thruster == null)
            {
                return(false);
            }

            bool autopilotEnabled = false;
            MyEntityThrustComponent thrustComp;

            if (thruster.CubeGrid.Components.TryGet(out thrustComp))
            {
                autopilotEnabled = thrustComp.AutopilotEnabled;
            }

            return(thruster.Enabled && thruster.IsFunctional && thruster.ThrustOverride > 0 && !autopilotEnabled);
        }
Exemplo n.º 9
0
        private float GetThrusterMaxForce(MyThrust thruster)
        {
            float thrusterForce = thruster.BlockDefinition.ForceMagnitude * (thruster as IMyThrust).ThrustMultiplier;

            if (thruster.BlockDefinition.EffectivenessAtMaxInfluence != 1f || thruster.BlockDefinition.EffectivenessAtMinInfluence != 1f)
            {
                if (!CapableAtmo && thruster.BlockDefinition.EffectivenessAtMaxInfluence > thruster.BlockDefinition.EffectivenessAtMinInfluence)
                {
                    CapableAtmo = true;
                }

                if (!CapableSpace && thruster.BlockDefinition.EffectivenessAtMinInfluence > thruster.BlockDefinition.EffectivenessAtMaxInfluence)
                {
                    CapableSpace = true;
                }

                if (m_airDensity <= thruster.BlockDefinition.MinPlanetaryInfluence)
                {
                    thrusterForce *= thruster.BlockDefinition.EffectivenessAtMinInfluence;
                }
                else if (m_airDensity >= thruster.BlockDefinition.MaxPlanetaryInfluence)
                {
                    thrusterForce *= thruster.BlockDefinition.EffectivenessAtMaxInfluence;
                }
                else
                {
                    float effectRange    = thruster.BlockDefinition.EffectivenessAtMaxInfluence - thruster.BlockDefinition.EffectivenessAtMinInfluence;
                    float influenceRange = thruster.BlockDefinition.MaxPlanetaryInfluence - thruster.BlockDefinition.MinPlanetaryInfluence;
                    float effectiveness  = (m_airDensity - thruster.BlockDefinition.MinPlanetaryInfluence) * effectRange / influenceRange + thruster.BlockDefinition.EffectivenessAtMinInfluence;
                    //Log.DebugLog("for thruster " + thruster.DisplayNameText + ", effectiveness: " + effectiveness + ", max force: " + thrusterForce + ", effect range: " + effectRange + ", influence range: " + influenceRange);
                    thrusterForce *= effectiveness;
                }
            }
            else
            {
                CapableAtmo  = true;
                CapableSpace = true;
            }
            return(thrusterForce);
        }
Exemplo n.º 10
0
        public void AddNewThruster(MyThrust myThrust)
        {
            if (myThrust == null || _thisIController == null)
            {
                return;
            }
            ControllableThruster thruster = null;

            if (_thisIController.WorldMatrix.Forward * -1 == myThrust.WorldMatrix.Forward)
            {
                thruster = new ControllableThruster(myThrust, ThrustDirection.Forward);
            }
            if (_thisIController.WorldMatrix.Backward * -1 == myThrust.WorldMatrix.Forward)
            {
                thruster = new ControllableThruster(myThrust, ThrustDirection.Back);
            }
            if (_thisIController.WorldMatrix.Left * -1 == myThrust.WorldMatrix.Forward)
            {
                thruster = new ControllableThruster(myThrust, ThrustDirection.Left);
            }
            if (_thisIController.WorldMatrix.Right * -1 == myThrust.WorldMatrix.Forward)
            {
                thruster = new ControllableThruster(myThrust, ThrustDirection.Right);
            }
            if (_thisIController.WorldMatrix.Up * -1 == myThrust.WorldMatrix.Forward)
            {
                thruster = new ControllableThruster(myThrust, ThrustDirection.Up);
            }
            if (_thisIController.WorldMatrix.Down * -1 == myThrust.WorldMatrix.Forward)
            {
                thruster = new ControllableThruster(myThrust, ThrustDirection.Down);
            }
            if (thruster == null)
            {
                return;
            }
            thruster.OnClose += CloseThruster;
            _thrusters[thruster.ThrustDirection].Add(thruster);
            RecalculateMaxEffectiveThrust();
        }
Exemplo n.º 11
0
        /// <summary>
        /// if removed is a thruster, remove it from thrustersInDirection
        /// </summary>
        /// <remarks>
        /// if a working block is destroyed, block_IsWorkingChange() is called first
        /// </remarks>
        /// <param name="removed">block that was removed</param>
        private void grid_OnBlockRemoved(IMySlimBlock removed)
        {
            try
            {
                if (removed.FatBlock == null)
                {
                    return;
                }

                MyThrust asThrust = removed.FatBlock as MyThrust;
                if (asThrust == null)
                {
                    return;
                }

                using (lock_thrustersInDirection.AcquireExclusiveUsing())
                    m_thrustersInDirection[(int)Base6Directions.GetFlippedDirection(asThrust.Orientation.Forward)].Remove(asThrust);
                Log.DebugLog("removed thruster = " + removed.FatBlock.DefinitionDisplayNameText + "/" + asThrust.DisplayNameText, Logger.severity.DEBUG);
                return;
            }
            catch (Exception e)
            { Log.AlwaysLog("Exception: " + e, Logger.severity.ERROR); }
        }
Exemplo n.º 12
0
 public MySyncThruster(MyThrust block)
 {
     m_block = block;
 }
Exemplo n.º 13
0
 public static float CalculatedCurrentPower(MyThrust thruster)
 {
     return((((IMyThrust)thruster).CurrentThrust / ((IMyThrust)thruster).MaxThrust) * thruster.MaxPowerConsumption);
 }
Exemplo n.º 14
0
 public override void Close()
 {
     linkedThruster = null;
 }
Exemplo n.º 15
0
 public static float CalculatedMaxThrust(MyThrust thruster, bool inAtmosphere)
 {
     return(thruster.BlockDefinition.ForceMagnitude * ((IMyThrust)thruster).ThrustMultiplier * CalculatedThrustScalar(thruster, inAtmosphere));
 }
Exemplo n.º 16
0
 public static float AdjustedMaxPower(MyThrust thruster, bool inAtmosphere)
 {           // Atmospheric thrusters get scaled based on where in the atmospheric layer they are
     return(thruster.MaxPowerConsumption * CalculatedThrustScalar(thruster, inAtmosphere));
 }
Exemplo n.º 17
0
 public MyDebugRenderComponentThrust(MyThrust thrust) : base(thrust)
 {
     this.m_thrust = thrust;
 }
Exemplo n.º 18
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                if (!block.IsFunctional) // only works if it's at full integrity, power status is irelevant
                {
                    return;
                }

                MyCubeGrid grid = block.CubeGrid;

                if (grid.Physics == null || !grid.Physics.Enabled)
                {
                    return;
                }

                if (linkedThruster == null)
                {
                    if (++linkSkip >= 60)
                    {
                        linkSkip = 0;
                        Vector3I     pos    = grid.WorldToGridInteger(block.WorldMatrix.Translation + block.WorldMatrix.Backward * grid.GridSize);
                        IMySlimBlock slim   = grid.GetCubeBlock(pos) as IMySlimBlock;
                        MyThrust     thrust = slim?.FatBlock as MyThrust;

                        if (thrust != null)
                        {
                            double alignDot = Math.Round(Vector3.Dot(thrust.WorldMatrix.Backward, block.WorldMatrix.Backward), 1);

                            if (alignDot == 1 && ThrustReversersMod.Instance.LinkableThrusters.Contains(thrust.BlockDefinition.Id.SubtypeName))
                            {
                                linkedThruster = thrust;

                                ThrustBlock logic = linkedThruster.GameLogic.GetAs <ThrustBlock>();
                                logic.Reverser = this;
                            }
                        }
                    }

                    return;
                }

                if (linkedThruster.Closed || linkedThruster.MarkedForClose)
                {
                    linkedThruster = null;
                    return;
                }

                if (!linkedThruster.IsWorking)
                {
                    return;
                }

                float closedRatio = (block.FullyClosed ? 1 : (block.FullyOpen ? 0 : (1 - (block.OpenRatio / def.OpeningSequence[0].MaxOpen)))); // HACK OpenRatio fix

                ReflectedThrust = Math.Max(closedRatio - 0.4f, 0) / 0.6f;

                if (ReflectedThrust > 0 && linkedThruster.CurrentStrength > 0)
                {
                    Vector3D force   = linkedThruster.WorldMatrix.Forward * linkedThruster.BlockDefinition.ForceMagnitude * linkedThruster.CurrentStrength * 1.75 * ReflectedThrust;
                    Vector3D forceAt = (ThrustReversersMod.Instance.RealisticThrustersInstalled ? linkedThruster.WorldMatrix.Translation : grid.Physics.CenterOfMassWorld); // Realistic Thrusters Mod support
                    grid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force, forceAt, null);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 19
0
 public bool IsRegistered(MyThrust thrust)
 {
     Debug.Assert(thrust != null);
     return(m_thrustsByDirection[thrust.ThrustForwardVector].Contains(thrust));
 }
Exemplo n.º 20
0
 private static bool IsOverridden(MyThrust thrust)
 {
     return(thrust.Enabled && thrust.IsFunctional && thrust.ThrustOverride > 0);
 }
Exemplo n.º 21
0
 // ReSharper disable once InconsistentNaming
 private static void InitPatch(MyThrust __instance)
 {
     _thrustOverride.GetSync <float>(__instance).ValueChangedInRange(0, 100);
 }
Exemplo n.º 22
0
 public ThrustWrapper(MySlimBlock block) : base(block)
 {
     Block = (MyThrust)block.FatBlock;
 }
Exemplo n.º 23
0
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     Block = (MyThrust)Entity;
     Block.IsWorkingChanged += WorkingChanged;
 }
Exemplo n.º 24
0
        public override void UpdateOnceBeforeFrame()
        {
            try
            {
                if (ThrustReversersMod.Instance == null || !ThrustReversersMod.Instance.IsPlayer)
                {
                    return;
                }

                thrust = (MyThrust)Entity;
                MyCubeGrid grid = thrust.CubeGrid;

                if (grid?.Physics == null || !grid.Physics.Enabled)
                {
                    return;
                }

                ThrustReversersMod.Instance.ThrustLogicDraw.Add(this);

                switch (thrust.BlockDefinition.Id.SubtypeName)
                {
                case "LargeBlockLargeAtmosphericThrust":
                    maxViewDistSq  = 1200;
                    length         = 5f;
                    thickness      = 1.6f;
                    trailOffset    = -3f;
                    lightOffset    = 0.75f;
                    lightJetOffset = 1.75f;
                    pointOffset    = 0f;
                    pointScaleMul  = 1.3f;
                    coneOffset     = -3.5f;
                    coneHeight     = 18f;
                    coneRadius     = 2.65f;
                    break;

                case "LargeBlockSmallAtmosphericThrust":
                    maxViewDistSq  = 800;
                    length         = 3f;
                    thickness      = 0.5f;
                    trailOffset    = -1f;
                    lightOffset    = 0f;
                    lightJetOffset = 1.75f;
                    pointOffset    = 0f;
                    pointScaleMul  = 1.4f;
                    coneOffset     = -1.75f;
                    coneHeight     = 10f;
                    coneRadius     = 0.8f;
                    break;

                case "SmallBlockLargeAtmosphericThrust":
                    maxViewDistSq  = 500;
                    length         = 1f;
                    thickness      = 0.325f;
                    trailOffset    = -0.5f;
                    lightOffset    = 0.75f;
                    lightJetOffset = 1.75f;
                    pointOffset    = 0.325f;
                    pointScaleMul  = 1.1f;
                    coneOffset     = 0f;
                    coneHeight     = 2f;
                    coneRadius     = 0.4225f;
                    break;

                case "SmallBlockSmallAtmosphericThrust":
                    maxViewDistSq  = 300;
                    length         = 0.75f;
                    thickness      = 0.1f;
                    trailOffset    = -0.5f;
                    lightOffset    = 0.75f;
                    lightJetOffset = 1.5f;
                    pointOffset    = 0.15f;
                    pointScaleMul  = 1.4f;
                    coneOffset     = -0.05f;
                    coneHeight     = 1.2f;
                    coneRadius     = 0.15f;
                    break;
                }

                maxViewDistSq *= maxViewDistSq;

                light = MyLights.AddLight();
                light.Start("ThrustLight");
                light.LightOn = false;

                lightJet = MyLights.AddLight();
                lightJet.Start("ThrustJetLight");
                lightJet.LightOn = false;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 25
0
 private static bool IsOverridden(MyThrust thrust)
 {
     return(thrust.Enabled && thrust.IsFunctional && thrust.ThrustOverride > 0 && !thrust.CubeGrid.GridSystems.ThrustSystem.AutopilotEnabled);
 }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_thrust = Container.Entity as MyThrust;
 }
Exemplo n.º 27
0
 private static bool IsUsed(MyThrust thrust)
 {
     // Overridden thrusts are calculated separately
     return(thrust.Enabled && thrust.IsFunctional && thrust.ThrustOverride == 0);
 }
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     Block        = (MyThrust)Entity;
     NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
 }
 public override void OnAddedToContainer(MyComponentContainer container)
 {
     base.OnAddedToContainer(container);
     m_thrust = Entity as MyThrust;
 }