Ejemplo n.º 1
0
 private static void Entities_OnCloseAll()
 {
     MyAPIGateway.Entities.OnCloseAll -= Entities_OnCloseAll;
     DoTests  = null;
     Path     = null;
     Timer    = null;
     s_logger = null;
 }
Ejemplo n.º 2
0
        private void OnOreSearchComplete(bool success, Vector3D orePosition, IMyVoxelBase foundMap, string oreName)
        {
            if (!success)
            {
                m_logger.debugLog("No ore target found", Logger.severity.INFO);
                m_navSet.OnTaskComplete_NavRot();
                m_navSet.Settings_Commands.Complaint = InfoString.StringId.NoOreFound;
                return;
            }

            m_targetVoxel = foundMap;
            m_depositPos  = orePosition;
            m_depositOre  = oreName;

            Vector3 toCentre = Vector3.Normalize(m_targetVoxel.GetCentre() - m_depositPos);

            GetExteriorPoint(m_depositPos, toCentre, m_longestDimension, exterior => {
                m_approach = new LineSegmentD(exterior - toCentre * m_longestDimension * 5f, exterior);
                m_state    = State.Approaching;
                m_logger.debugLog("approach: " + m_approach.From.ToGpsTag("From") + ", " + m_approach.To.ToGpsTag("To"));
            });
        }
Ejemplo n.º 3
0
 private static void Entities_OnCloseAll()
 {
     MyAPIGateway.Entities.OnCloseAll -= Entities_OnCloseAll;
     DoTests = null;
     Path = null;
     Timer = null;
     s_logger = null;
 }
Ejemplo n.º 4
0
		public bool GravityTest(LineSegmentD line, Vector3D finalDestination, out MyEntity blockingPath, out Vector3? pointOfObstruction)
		{
			if (Vector3.DistanceSquared(line.From, line.To) > 10000f)
			{
				BoundingBoxD box = line.BoundingBox;
				m_voxels.Clear();
				MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, m_voxels);

				foreach (MyEntity entity in m_voxels)
				{
					MyPlanet planet = entity as MyPlanet;
					if (planet == null)
						continue;

					Vector3D planetCentre = planet.GetCentre();
					Vector3D closestPoint = line.ClosestPoint(planetCentre);

					if (!planet.IsPositionInGravityWell(closestPoint))
						continue;

					m_logger.debugLog("path: " + line.From + " to " + line.To + ", final: " + finalDestination + ", closest point: " + closestPoint + ", planet @ " + planetCentre + " : " + planet.getBestName(), "GravityTest()");
			
					if (closestPoint == line.From)
					{
						m_logger.debugLog("closest point is start", "GravityTest()");
						continue;
					}
					if (closestPoint == line.To)
					{
						if (line.To == finalDestination )
						{
							m_logger.debugLog("closest point is final", "GravityTest()");
							continue;
						}
						if (Vector3D.DistanceSquared(planetCentre, closestPoint) < Vector3D.DistanceSquared(planetCentre, finalDestination))
						{
							m_logger.debugLog("closest point is end, which is closer to planet than final dest is", "GravityTest()");
							blockingPath = entity;
							pointOfObstruction = closestPoint;
							return false;
						}
						m_logger.debugLog("closest point is end", "GravityTest()");
						continue;
					}

					//float startGravity = planet.GetWorldGravityGrid( line.From).LengthSquared();
					//float closestGravity = planet.GetWorldGravityGrid(closestPoint).LengthSquared();

					//double toDistSq = Vector3D.DistanceSquared(planetCentre, line.To);

					//if (closestPoint == line.To && (line.To == finalDestination ||     ))
					//{
					//	m_logger.debugLog("path: " + line.From + " to " + line.To + ", closest point: " + closestPoint + ", planet @ " + planetCentre + " : " + planet.getBestName(), "GravityTest()");
					//	m_logger.debugLog("closest point is end", "GravityTest()");
					//	continue;
					//}

					//m_logger.debugLog("path: " + line.From + " to " + line.To + ", closest point: " + closestPoint + ", planet @ " + planetCentre + " : " + planet.getBestName(), "GravityTest()", Logger.severity.DEBUG);


					double closestDistSq = Vector3D.DistanceSquared(planetCentre, closestPoint) + 1f;
					if (closestDistSq < Vector3D.DistanceSquared(planetCentre, line.From) || closestDistSq < Vector3D.DistanceSquared(planetCentre, line.To))
					{
						m_logger.debugLog("path moves ship closer to planet. closestDistSq: " + closestDistSq + ", from dist sq: " + Vector3D.DistanceSquared(planetCentre, line.From) + ", to dist sq: " + Vector3D.DistanceSquared(planetCentre, line.To), "GravityTest()", Logger.severity.INFO);
						blockingPath = entity;
						pointOfObstruction = closestPoint;
						return false;
					}
				}
			}

			blockingPath = null;
			pointOfObstruction = null;
			return true;
		}
Ejemplo n.º 5
0
 public RailData(Vector3D start)
 {
     RailStart = start;
     Rail      = new LineSegmentD();
     Created   = Globals.ElapsedTime;
 }
Ejemplo n.º 6
0
 public RailData(Vector3D start)
 {
     RailStart = start;
     Rail = new LineSegmentD();
     Created = Globals.ElapsedTime;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Subpart of Mover() that runs when ship is inside destination radius.
        /// </summary>
        private void Move_Land()
        {
            if (IsLocked())
            {
                Log.DebugLog("Attached!", Logger.severity.INFO);
                m_navSet.OnTaskComplete(m_settingLevel);
                UnreserveTarget();
                m_mover.StopMove(false);
                m_mover.StopRotate();
                if (m_navSet.Shopper != null)
                {
                    Log.DebugLog("starting shopper");
                    m_navSet.Shopper.Start();
                }
                return;
            }

            switch (m_landingState)
            {
            case LandingState.None:
            {
                throw new Exception("landing state is None");
            }

            case LandingState.Approach:
            {
                m_navSet.GetSettingsLevel(m_settingLevel).NavigatorRotator = this;
                m_navSet.GetSettingsLevel(m_settingLevel).NavigationBlock  = m_navBlock;
                if (m_landGearWithoutTargetBlock)
                {
                    m_landingState = LandingState.Catch;
                    goto case LandingState.Catch;
                }
                else
                {
                    m_landingState = LandingState.Holding;
                    goto case LandingState.Holding;
                }
            }

            case LandingState.Holding:
            {
                if (m_gridFinder.Block != null && ReserveTarget(m_gridFinder.Block.EntityId))
                {
                    Log.DebugLog("Have a block, starting landing sequence", Logger.severity.DEBUG);
                    m_landingState = LandingState.LineUp;
                    return;
                }
                m_pathfinder.HoldPosition(m_gridFinder.Grid);
                return;
            }

            case LandingState.LineUp:
            {
                if (m_gridFinder.Block == null)
                {
                    Log.DebugLog("lost block");
                    m_landingState = LandingState.Holding;
                    return;
                }

                if (m_navSet.DirectionMatched())
                {
                    if (m_navSet.Settings_Current.Distance < 1f)
                    {
                        Log.DebugLog("Reached line: " + m_navSet.Settings_Current.Distance);
                        m_landingState = LandingState.Landing;
                        return;
                    }
                }
                //else if (m_pathfinder.RotateCheck.ObstructingEntity != null)
                //{
                //	Vector3D destinationWorld = m_destination.WorldPosition();
                //	Vector3 directAway = m_navBlock.WorldPosition - destinationWorld;
                //	if (directAway.LengthSquared() < 1)
                //	{
                //		destinationWorld = m_gridFinder.Grid.Entity.WorldAABB.Center;
                //		directAway = m_navBlock.WorldPosition - destinationWorld;
                //	}
                //	Vector3D targetPosition = destinationWorld + Vector3.Normalize(directAway) * m_navSet.Settings_Current.DestinationRadius;

                //	Log.DebugLog("Pathfinder cannot rotate, moving away. destination: " + destinationWorld + ", directAway: " + Vector3.Normalize(directAway) +
                //		", DestinationRadius: " + m_navSet.Settings_Current.DestinationRadius + ", targetPosition: " + targetPosition);

                //	m_destination.SetWorld(ref targetPosition);
                //	m_pathfinder.MoveTo(destinations: m_destination);
                //	return;
                //}
                else if (m_navSet.Settings_Current.Distance < 1f)
                {
                    // replace do nothing (line) or other rotator that is preventing ship from landing
                    m_navSet.Settings_Task_NavWay.NavigatorRotator = this;
                }

                // move to line from target block outwards
                Vector3D     landFaceVector  = GetLandingFaceVector();
                float        distanceBetween = m_gridFinder.Block.GetLengthInDirection(m_landingDirection) * 0.5f + m_landingHalfSize + 1f;
                Vector3D     destWorld       = m_destination.WorldPosition();
                LineSegmentD destinationLine = new LineSegmentD(destWorld + landFaceVector * distanceBetween, destWorld + landFaceVector * 1000f);

                Vector3D closestPoint = destinationLine.ClosestPoint(m_navBlock.WorldPosition);

                Log.DebugLog("Flying to closest point to " + m_navBlock.WorldPosition + " on line between " + destinationLine.From + " and " + destinationLine.To + " which is " + closestPoint);
                Log.DebugLog("missing block", Logger.severity.ERROR, condition: m_gridFinder.Block == null);
                m_destination = Destination.FromWorld(m_gridFinder.Block, closestPoint);
                m_pathfinder.MoveTo(destinations: m_destination);
                return;
            }

            case LandingState.Landing:
            {
                if (m_gridFinder.Block == null)
                {
                    Log.DebugLog("lost block");
                    m_landingState = LandingState.Holding;
                    return;
                }

                if (m_navSet.Settings_Current.DistanceAngle > 0.1f)
                {
                    Log.DebugLog("waiting for direction to match");
                    m_pathfinder.HoldPosition(m_gridFinder.Grid);
                    return;
                }

                LockConnector();

                float distanceBetween = m_gridFinder.Block.GetLengthInDirection(m_landingDirection) * 0.5f + m_landingHalfSize + 0.1f;
                //Log.DebugLog("moving to " + (m_targetPosition + GetLandingFaceVector() * distanceBetween) + ", distance: " + m_navSet.Settings_Current.Distance, "Move_Land()");

                //if (m_navSet.DistanceLessThan(1f))
                //{
                //	m_landingSpeedFudge += 0.0001f;
                //	if (m_landingSpeedFudge > 0.1f)
                //		m_landingSpeedFudge = -0.1f;
                //}

                m_destination.Position += GetLandingFaceVector() * distanceBetween;
                m_pathfinder.MoveTo(destinations: m_destination);
                return;
            }

            case LandingState.Catch:
            {
                if (m_navSet.Settings_Current.DistanceAngle > 0.1f)
                {
                    Log.DebugLog("waiting for direction to match");
                    m_pathfinder.HoldPosition(m_gridFinder.Grid);
                    return;
                }

                //if (m_navSet.DistanceLessThan(1f))
                //{
                //	m_landingSpeedFudge += 0.0001f;
                //	if (m_landingSpeedFudge > 0.1f)
                //		m_landingSpeedFudge = -0.1f;
                //	Log.DebugLog("target position: " + m_destination.WorldPosition() + ", nav position: " + m_navBlock.WorldPosition + ", distance: " + Vector3D.Distance(m_destination.WorldPosition(), m_navBlock.WorldPosition) + "/" + m_navSet.Settings_Current.Distance + ", fudge: " + m_landingSpeedFudge);
                //}
                //m_destination.Position += m_gridFinder.Grid.GetLinearVelocity() * m_landingSpeedFudge;
                m_pathfinder.MoveTo(destinations: m_destination);
                return;
            }
            }
        }
Ejemplo n.º 8
0
        private void OnOreSearchComplete(bool success, Vector3D orePosition, IMyVoxelBase foundMap, string oreName)
        {
            if (!success)
            {
                m_logger.debugLog("No ore target found", Logger.severity.INFO);
                m_navSet.OnTaskComplete_NavRot();
                m_navSet.Settings_Commands.Complaint = "No ore found";
                return;
            }

            m_targetVoxel = foundMap;
            m_depositPos = orePosition;
            m_depositOre = oreName;

            Vector3 toCentre = Vector3.Normalize(m_targetVoxel.GetCentre() - m_depositPos);
            GetExteriorPoint(m_depositPos, toCentre, m_longestDimension, exterior => {
                m_approach = new LineSegmentD(exterior - toCentre * m_longestDimension * 5f, exterior);
                m_state = State.Approaching;
                m_logger.debugLog("approach: " + m_approach.From.ToGpsTag("From") + ", " + m_approach.To.ToGpsTag("To"));
            });
        }