public ControllableThruster(IMyThrust thisThruster, ThrustDirection thisDirection)
 {
     _thisIThruster         = thisThruster;
     ThrustDirection        = thisDirection;
     _thisThruster          = (MyThrust)thisThruster;
     _thisDefinition        = _thisThruster.BlockDefinition;
     _thisThruster.OnClose += Close;
 }
 private void SetBalancedThrust(ThrustDirection direction, float value)
 {
     if (IsClosed)
     {
         return;
     }
     if (_maxEffectiveThrust[direction] - _currentlyUtilizedThrust[direction] > value)
     {
         InsufficientThrustAvailable?.Invoke(direction);
     }
     foreach (ControllableThruster thruster in _thrusters[direction])
     {
         thruster.SetThrust(value / _thrusters[direction].Count);
     }
     _currentlyUtilizedThrust[direction] = value;
 }
        private void SetRollingThrust(ThrustDirection direction, float value)
        {
            if (IsClosed)
            {
                return;
            }
            float tmpValue = value;

            _currentlyUtilizedThrust[direction] = 0;
            foreach (ControllableThruster thruster in _thrusters[direction])
            {
                if (Math.Abs(value) <= 0)
                {
                    thruster.SetThrust(0);
                    continue;
                }

                float availableThrust = thruster.MaxThrust() - thruster.CurrentThrust();
                if (availableThrust <= 0)
                {
                    continue;
                }

                if (availableThrust > tmpValue)
                {
                    thruster.SetThrust(thruster.CurrentThrust() + tmpValue);
                    tmpValue = 0;
                }
                else
                {
                    thruster.SetThrust(thruster.MaxThrust());
                    tmpValue -= thruster.MaxThrust();
                }
                if (tmpValue > 0)
                {
                    continue;
                }
                thruster.SetThrust(0);
            }
            if (tmpValue > 0)
            {
                InsufficientThrustAvailable?.Invoke(direction);
                _currentlyUtilizedThrust[direction] = value - tmpValue;
                return;
            }
            _currentlyUtilizedThrust[direction] = value;
        }
        public void SetThrust(ThrustDirection direction, float value)
        {
            if (Math.Sign(value) < 0)
            {
                value = Math.Abs(value);
                // If we're requesting negative thrust on this axis, then any
                //	thrust on this axis in the requested direction needs to be nullified
                // Remember, this is a set, not an accumulated value
                SetThrust(direction, 0);
                switch (direction)
                {
                case ThrustDirection.Up:
                    direction = ThrustDirection.Down;
                    break;

                case ThrustDirection.Down:
                    direction = ThrustDirection.Up;
                    break;

                case ThrustDirection.Left:
                    direction = ThrustDirection.Right;
                    break;

                case ThrustDirection.Right:
                    direction = ThrustDirection.Left;
                    break;

                case ThrustDirection.Forward:
                    direction = ThrustDirection.Back;
                    break;

                case ThrustDirection.Back:
                    direction = ThrustDirection.Forward;
                    break;

                default:
                    return;                             // something is broken if this ever happens, so... ignore it.
                }
            }
            SetRollingThrust(direction, value);
        }
Example #5
0
 public void SetThrustDirection(ThrustDirection direction)
 {
     isReversing = direction == ThrustDirection.Backwards;
 }
Example #6
0
 private bool thrusterBurning(ThrustDirection dir)
 {
     return thrusterLastActive[dir]+thrusterBurnTime >= gameTime;
 }
Example #7
0
 private bool thrusterActive(ThrustDirection dir)
 {
     return thrusterLastActive[dir] == gameTime;
 }
Example #8
0
 private void fireThruster(ThrustDirection dir)
 {
     thrusterLastActive[dir] = gameTime;
     if(Thrust != null) Thrust(this, new EventArgs());
 }
 public float GetMaxEffectiveThrustInDirection(ThrustDirection direction)
 {
     return(_maxEffectiveThrust[direction]);
 }