Example #1
0
        private void CalculateThrustMultiplier()
        {
            MaxMultiplier = m_minMultiplier * Overclock;

            if (!SafetySwitch)
            {
                CurrentMultiplier = MaxMultiplier;
            }
            else if (m_heat > m_maxHeat)
            {
                CurrentMultiplier = Math.Max(m_minMultiplier, m_iThrust.ThrustMultiplier - (m_heat / m_maxHeat));
            }
            else
            {
                CurrentMultiplier = Math.Min(MaxMultiplier, m_iThrust.ThrustMultiplier + (m_maxHeat / m_heat + 1));
            }

            var message = new MessageThrusterVariables();

            message.EntityId         = m_entityId;
            message.ThrustMultiplier = CurrentMultiplier;
            message.Overclock        = Overclock;
            message.SafetySwitch     = SafetySwitch;

            if (!Core.Instance.CubeGridInfo.ContainsKey(_cubeGridEntityId))
            {
                Messaging.SendMessageToAllPlayers(message);
            }
            else
            {
                Messaging.SendMessageToConcurrentPlayerList(message, Core.Instance.CubeGridInfo[_cubeGridEntityId].PlayersInSyncRange);
            }
        }
Example #2
0
        private void InitControls()
        {
            ThrusterOverclock         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyThrust>("Overclock");
            ThrusterOverclock.Title   = MyStringId.GetOrCompute("Overclock");
            ThrusterOverclock.Tooltip = MyStringId.GetOrCompute("Multiplies thruster power at the cost of heat and degradation.");
            ThrusterOverclock.SetLimits(1, maxThrusterOverclock);
            ThrusterOverclock.SupportsMultipleBlocks = true;
            ThrusterOverclock.Getter = (x) =>
            {
                if (x == null || x.GameLogic == null)
                {
                    return(1f);
                }

                var logic = x.GameLogic.GetAs <ThrustOverride>();

                return(logic != null ? logic.Overclock : 1f);
            };

            ThrusterOverclock.Setter = (x, y) =>
            {
                var logic = x.GameLogic.GetAs <ThrustOverride>();

                if (logic != null)
                {
                    logic.Overclock = y;

                    if (Sync.IsClient)
                    {
                        var message = new MessageThrusterVariables();
                        message.EntityId         = logic.Entity.EntityId;
                        message.UpdateCustomData = true;
                        message.Overclock        = logic.Overclock;
                        message.SafetySwitch     = logic.SafetySwitch;
                        Messaging.SendMessageToServer(message);
                    }
                }
            };

            ThrusterOverclock.Writer = (x, y) =>
            {
                if (x == null || x.GameLogic == null)
                {
                    return;
                }

                var logic = x.GameLogic.GetAs <ThrustOverride>();

                if (logic != null)
                {
                    y.Append(logic.Overclock.ToString() + "x");
                }
            };

            SafetySwitch         = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlOnOffSwitch, IMyThrust>("SafetySwitch");
            SafetySwitch.Title   = MyStringId.GetOrCompute("Safety Switch");
            SafetySwitch.Tooltip = MyStringId.GetOrCompute("When enabled, reduces thrust when necessary to prevent damage from excessive heat.\nTurning this off can allow steady thrust over longer periods of time,\nwhich can be useful in emergencies.");
            SafetySwitch.OnText  = MyStringId.GetOrCompute("On");
            SafetySwitch.OffText = MyStringId.GetOrCompute("Off");
            SafetySwitch.SupportsMultipleBlocks = true;

            SafetySwitch.Getter = x =>
            {
                if (x == null || x.GameLogic == null)
                {
                    return(true);
                }

                var logic = x.GameLogic.GetAs <ThrustOverride>();

                return(logic != null ? logic.SafetySwitch : true);
            };

            SafetySwitch.Setter = (x, y) =>
            {
                Debug.Write("Attempting to set safety switch", 1);
                if (x == null || x.GameLogic == null)
                {
                    return;
                }

                var logic = x.GameLogic.GetAs <ThrustOverride>();

                logic.SafetySwitch = y;

                if (Sync.IsClient)
                {
                    Debug.Write("Set safety switch on client", 1);
                }

                if (Sync.IsServer)
                {
                    Debug.Write("Set safety switch on server", 1);
                }

                if (Sync.IsClient)
                {
                    var message = new MessageThrusterVariables();
                    message.UpdateCustomData = true;
                    message.EntityId         = logic.Entity.EntityId;
                    message.Overclock        = logic.Overclock;
                    message.SafetySwitch     = logic.SafetySwitch;
                    Messaging.SendMessageToServer(message);
                }
            };

            safetySwitchAction         = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("SafetySwitchAction");
            safetySwitchAction.Enabled = (x) => true;
            safetySwitchAction.Name    = new StringBuilder(string.Format("Safety Toggle On/Off"));
            safetySwitchAction.Icon    = @"Textures\GUI\Icons\Actions\Toggle.dds";
            safetySwitchAction.Action  = (x) =>
            {
                if (x == null || SafetySwitch == null)
                {
                    return;
                }

                SafetySwitch.Setter(x, !SafetySwitch.Getter(x));
            };
            safetySwitchAction.ValidForGroups = true;
            safetySwitchAction.Writer         = (x, y) =>
            {
                if (x == null || SafetySwitch == null)
                {
                    return;
                }

                y.Append(SafetySwitch.Getter(x) ? "On" : "Off");
            };
            safetySwitchAction.InvalidToolbarTypes = new List <MyToolbarType>();

            overclockActionIncrease                = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("OverclockActionIncrease");
            overclockActionIncrease.Enabled        = (x) => true;
            overclockActionIncrease.Name           = new StringBuilder(string.Format("Increase Overclock"));
            overclockActionIncrease.Icon           = @"Textures\GUI\Icons\Actions\Increase.dds";
            overclockActionIncrease.ValidForGroups = true;
            overclockActionIncrease.Action         = (x) =>
            {
                if (x == null || ThrusterOverclock == null)
                {
                    return;
                }

                ThrusterOverclock.Setter(x, Math.Min(ThrusterOverclock.Getter(x) + 1f, maxThrusterOverclock));
            };
            overclockActionIncrease.Writer = (x, y) =>
            {
                if (x == null || ThrusterOverclock == null)
                {
                    return;
                }
                y.Append(ThrusterOverclock.Getter(x).ToString() + "x");
            };
            overclockActionIncrease.InvalidToolbarTypes = new List <MyToolbarType>();

            overclockActionDecrease                = MyAPIGateway.TerminalControls.CreateAction <IMyThrust>("OverclockActionDecrease");
            overclockActionDecrease.Enabled        = (x) => true;
            overclockActionDecrease.Name           = new StringBuilder(string.Format("Decrease Overclock"));
            overclockActionDecrease.Icon           = @"Textures\GUI\Icons\Actions\Decrease.dds";
            overclockActionDecrease.ValidForGroups = true;
            overclockActionDecrease.Action         = (x) =>
            {
                if (x == null || ThrusterOverclock == null)
                {
                    return;
                }

                ThrusterOverclock.Setter(x, Math.Max(ThrusterOverclock.Getter(x) - 1f, 1f));
            };
            overclockActionDecrease.Writer = (x, y) =>
            {
                if (x == null || ThrusterOverclock == null)
                {
                    return;
                }
                y.Append(ThrusterOverclock.Getter(x).ToString() + "x");
            };
            overclockActionDecrease.InvalidToolbarTypes = new List <MyToolbarType>();
        }