Exemplo n.º 1
0
        private bool ValidateLimits(float angleDegrees)
        {
            if (governing != null)
            {
                if (angleDegrees > governing.UpperLimitDeg)
                {
                    return(false);
                }
                if (angleDegrees < governing.LowerLimitDeg)
                {
                    return(false);
                }
            }

            if (opposing != null)
            {
                var opposingAngleDegrees = RotorLimits.OpposedAngleDegrees(angleDegrees);
                if (opposingAngleDegrees > opposing.UpperLimitDeg)
                {
                    return(false);
                }
                if (opposingAngleDegrees < opposing.LowerLimitDeg)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 public EngineModule(string moduleName, IFacingRotorPair rotorPair, RotorLimits limits, IMyThrust[] thrusters)
 {
     this.moduleName = moduleName;
     this.rotorPair  = rotorPair;
     this.limits     = limits;
     this.thrusters  = thrusters;
 }
Exemplo n.º 3
0
 private void UnlockAndPrepareForRotate(RotorLimits thisRotationLimits)
 {
     foreach (var thruster in thrusters)
     {
         thruster.Enabled = false;
     }
     rotorPair.ApplyLimits(thisRotationLimits);
     rotorPair.Unlock();
 }
Exemplo n.º 4
0
        public void CheckState(Errors errors, string owningModuleName)
        {
            if (governing == null)
            {
                errors.Warnings.Add(new Message("Governing rotor of module {0} is missing.", owningModuleName));
            }
            else if (!governing.IsOperational())
            {
                errors.Warnings.Add(new Message("Governing rotor {0} of module {1} is not operational.", governing.CustomName, owningModuleName));
            }
            else if (!governing.IsAttached)
            {
                errors.Warnings.Add(new Message("Governing rotor {0} of module {1} is not attached.", governing.CustomName, owningModuleName));
            }

            if (opposing == null)
            {
                errors.Warnings.Add(new Message("Opposing rotor of module {0} is missing.", owningModuleName));
            }
            else if (!opposing.IsOperational())
            {
                errors.Warnings.Add(new Message("Opposing rotor {0} of module {1} is not operational.", opposing.CustomName, owningModuleName));
            }
            else if (!opposing.IsAttached)
            {
                errors.Warnings.Add(new Message("Opposing rotor {0} of module {1} is not attached.", opposing.CustomName, owningModuleName));
            }

            if (!IsViable)
            {
                return;
            }

            if (governing?.IsAttached == true && opposing?.IsAttached == true)
            {
                if (governing.TopGrid != opposing.TopGrid)
                {
                    errors.SanityChecks.Add(new Message("Rotors of module {0} connect to different subgrids ({1} and {2}).", owningModuleName, governing.TopGrid.CustomName, opposing.TopGrid.CustomName));
                }
                else
                {
                    var governingDegrees = MathHelper.ToDegrees(governing.Angle);
                    var opposedDegrees   = RotorLimits.OpposedAngleDegrees(MathHelper.ToDegrees(opposing.Angle));
                    var rotorOffset      = RotorLimits.DifferenceDegrees(governingDegrees, opposedDegrees);
                    if (rotorOffset > 1)
                    {
                        errors.SanityChecks.Add(new Message("Rotors of module {0} are not properly synchronised: {1}.", owningModuleName, rotorOffset));
                    }
                }
            }

            if (!ValidateLimits(CurrentAngleDegrees))
            {
                errors.SafetyConcerns.Add(new Message("Rotors of module {0} are outside of set limits.", owningModuleName));
            }
        }
        private EngineModule BuildModule(StaticState.EngineModuleDef definition, RotorLimits limits, ref long hash)
        {
            var governing = gridTerminalSystem.GetBlockWithName(definition.GoverningRotorName) as IMyMotorStator;
            var opposing  = gridTerminalSystem.GetBlockWithName(definition.OpposingRotorName) as IMyMotorStator;

            AddToHash(ref hash, governing?.EntityId ?? 0);
            AddToHash(ref hash, opposing?.EntityId ?? 0);

            var thrusters = GetThrusters(governing, opposing);

            return(new EngineModule(definition.Name, new FacingRotorPair(governing, opposing), limits, thrusters));
        }
        public EngineTier Build(StaticState.EngineTierDef definition)
        {
            var hash    = 0L;
            var modules = new EngineModule[definition.Modules.Length];

            var limits = new RotorLimits(definition.Presets.Min(p => p.Angle), definition.Presets.Max(p => p.Angle));

            AddToHash(ref hash, limits.GetHashCode());

            for (var i = 0; i < definition.Modules.Length; i++)
            {
                modules[i] = BuildModule(definition.Modules[i], limits, ref hash);
            }
            return(new EngineTier(modules, definition.Presets, hash));
        }
Exemplo n.º 7
0
        public void ApplyLimits(RotorLimits newLimits)
        {
            // Set lower limits first, since upper limits might be clamped.
            if (governing != null)
            {
                governing.Displacement  = Constants.FACING_ROTOR_DISPLACEMENT;
                governing.LowerLimitDeg = newLimits.Minimum;
                governing.UpperLimitDeg = newLimits.Maximum;
            }

            if (opposing != null)
            {
                var newOpposingLimits = newLimits.Opposing();
                opposing.Displacement  = Constants.FACING_ROTOR_DISPLACEMENT;
                opposing.LowerLimitDeg = newOpposingLimits.Minimum;
                opposing.UpperLimitDeg = newOpposingLimits.Maximum;
            }
        }