Exemplo n.º 1
0
        private float CalcForceInDirection(Base6Directions.Direction direction)
        {
            float force = 0;

            using (lock_thrustersInDirection.AcquireSharedUsing())
                foreach (MyThrust thruster in m_thrustersInDirection[(int)direction])
                {
                    if (!thruster.Closed && thruster.IsWorking)
                    {
                        force += GetThrusterMaxForce(thruster);
                    }
                }

            m_totalThrustForce[(int)direction] = force;

            if (direction == m_primaryForce.Direction)
            {
                //Log.DebugLog("updating primary force, direction: " + direction + ", force: " + force, "CalcForceInDirection()");
                m_primaryForce.Force = force;
            }
            else if (force > m_primaryForce.Force * 1.1f)
            {
                Log.DebugLog("stronger than primary force, direction: " + direction + ", force: " + force + ", acceleration: " + force / myGrid.Physics.Mass + ", primary: " + m_primaryForce, Logger.severity.DEBUG);
                m_secondaryForce         = m_primaryForce;
                m_primaryForce.Direction = direction;
                m_primaryForce.Force     = force;

                if (m_secondaryForce.Direction == Base6Directions.GetFlippedDirection(m_primaryForce.Direction))
                {
                    m_secondaryForce = new ForceInDirection()
                    {
                        Direction = Base6Directions.GetPerpendicular(m_primaryForce.Direction)
                    }
                }
                ;

                Log.DebugLog("secondary: " + m_secondaryForce);

                Standard.SetMatrixOrientation(m_primaryForce.Direction, m_secondaryForce.Direction);
                Gravity.SetMatrixOrientation(m_secondaryForce.Direction, m_primaryForce.Direction);
            }
            else if (direction == m_secondaryForce.Direction)
            {
                //Log.DebugLog("updating secondary force, direction: " + direction + ", force: " + force, "CalcForceInDirection()");
                m_secondaryForce.Force = force;
            }
            else if (force > m_secondaryForce.Force * 1.1f && direction != Base6Directions.GetFlippedDirection(m_primaryForce.Direction))
            {
                Log.DebugLog("stronger than secondary force, direction: " + direction + ", force: " + force + ", acceleration: " + force / myGrid.Physics.Mass + ", secondary: " + m_secondaryForce, Logger.severity.DEBUG);
                m_secondaryForce.Direction = direction;
                m_secondaryForce.Force     = force;
                Standard.SetMatrixOrientation(m_primaryForce.Direction, m_secondaryForce.Direction);
                Gravity.SetMatrixOrientation(m_secondaryForce.Direction, m_primaryForce.Direction);
            }

            //Log.DebugLog("direction: " + direction + "(" + (int)direction + ")" + ", force: " + force);
            return(force);
        }
Exemplo n.º 2
0
        private float CalcForceInDirection(Base6Directions.Direction direction)
        {
            float force = 0;
            using (lock_thrustersInDirection.AcquireSharedUsing())
                foreach (MyThrust thruster in thrustersInDirection[direction])
                if (!thruster.Closed && thruster.IsWorking)
                    force += GetThrusterMaxForce(thruster);

            m_totalThrustForce[direction] = force;

            if (direction == m_primaryForce.Direction)
            {
                //myLogger.debugLog("updating primary force, direction: " + direction + ", force: " + force, "CalcForceInDirection()");
                m_primaryForce.Force = force;
            }
            else if (force > m_primaryForce.Force * 1.1f)
            {
                myLogger.debugLog("stronger than primary force, direction: " + direction + ", force: " + force + ", acceleration: " + force / myGrid.Physics.Mass + ", primary: " + m_primaryForce, Logger.severity.DEBUG);
                m_secondaryForce = m_primaryForce;
                m_primaryForce.Direction = direction;
                m_primaryForce.Force = force;

                if (m_secondaryForce.Direction == Base6Directions.GetFlippedDirection(m_primaryForce.Direction))
                    m_secondaryForce = new ForceInDirection() { Direction = Base6Directions.GetPerpendicular(m_primaryForce.Direction) };

                myLogger.debugLog("secondary: " + m_secondaryForce);

                Standard.SetMatrixOrientation(m_primaryForce.Direction, m_secondaryForce.Direction);
                Gravity.SetMatrixOrientation(m_secondaryForce.Direction, m_primaryForce.Direction);
            }
            else if (direction == m_secondaryForce.Direction)
            {
                //myLogger.debugLog("updating secondary force, direction: " + direction + ", force: " + force, "CalcForceInDirection()");
                m_secondaryForce.Force = force;
            }
            else if (force > m_secondaryForce.Force * 1.1f && direction != Base6Directions.GetFlippedDirection(m_primaryForce.Direction))
            {
                myLogger.debugLog("stronger than secondary force, direction: " + direction + ", force: " + force + ", acceleration: " + force / myGrid.Physics.Mass + ", secondary: " + m_secondaryForce, Logger.severity.DEBUG);
                m_secondaryForce.Direction = direction;
                m_secondaryForce.Force = force;
                Standard.SetMatrixOrientation(m_primaryForce.Direction, m_secondaryForce.Direction);
                Gravity.SetMatrixOrientation(m_secondaryForce.Direction, m_primaryForce.Direction);
            }

            return force;
        }