public void Reinit() { Debug.Assert(IsValid); if (m_endEntity != null) { m_destination.UpdateWorldTransform(m_endEntity.WorldMatrix); m_destinationCenter = m_destination.GetDestination(); } }
public MySmartGoal(IMyDestinationShape goal, MyEntity entity = null) { this.m_destination = goal; this.m_destinationCenter = goal.GetDestination(); this.m_endEntity = entity; if (this.m_endEntity != null) { this.m_destination.SetRelativeTransform(this.m_endEntity.PositionComp.WorldMatrixNormalizedInv); this.m_endEntity.OnClosing += new Action <MyEntity>(this.m_endEntity_OnClosing); } this.m_pathfindingHeuristic = new Func <MyNavigationPrimitive, float>(this.Heuristic); this.m_terminationCriterion = new Func <MyNavigationPrimitive, float>(this.Criterion); this.m_ignoredPrimitives = new HashSet <MyHighLevelPrimitive>(); this.IsValid = true; }
// MW:TODO optimize or change public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance) { m_reachPredicateDistance = thresholdDistance; var beginPrimitive = FindClosestPrimitive(begin, false); var endPrimitive = FindClosestPrimitive(end.GetDestination(), false); if (beginPrimitive == null || endPrimitive == null) { return(false); } var beginHL = beginPrimitive.GetHighLevelPrimitive(); var endHL = endPrimitive.GetHighLevelPrimitive(); ProfilerShort.Begin("HL"); MySmartGoal goal = new MySmartGoal(end); var path = goal.FindHighLevelPath(this, beginHL); ProfilerShort.End(); if (path == null) { return(false); } m_reachEndPrimitive = endPrimitive; ProfilerShort.Begin("Prepare for travesal"); PrepareTraversal(beginPrimitive, null, ReachablePredicate); ProfilerShort.End(); ProfilerShort.Begin("checking for vertices"); try { foreach (var vertex in this) { if (vertex.Equals(m_reachEndPrimitive)) { return(true); } } } finally { ProfilerShort.End(); } return(false); }
public bool GetNextTarget(Vector3D position, out Vector3D target, out float targetRadius, out IMyEntity relativeEntity) { target = Vector3D.Zero; relativeEntity = null; targetRadius = 0.8f; if (!m_isValid) { return(false); } if (m_pathPoints.Count == 0 || m_pathCompleted || !m_isValid) { m_pathPoints = m_pathfinding.GetPath(m_planet, position, m_destination.GetDestination()); if (m_pathPoints.Count < 2) { return(false); } // m_pathPoints[0] is the begin position m_currentPointIndex = 1; } if (m_currentPointIndex == m_pathPoints.Count - 1) { //try to generate more points by RequestPath(position, destination) } target = m_pathPoints[m_currentPointIndex]; // check distance if (Math.Abs(Vector3.Distance(target, position)) < targetRadius) { if (m_currentPointIndex == m_pathPoints.Count - 1) { m_pathCompleted = true; return(false); } else { m_currentPointIndex++; } target = m_pathPoints[m_currentPointIndex]; } return(true); }
public MySmartGoal(IMyDestinationShape goal, MyEntity entity = null) { m_destination = goal; m_destinationCenter = goal.GetDestination(); m_endEntity = entity; if (m_endEntity != null) { m_destination.SetRelativeTransform(m_endEntity.PositionComp.WorldMatrixNormalizedInv); m_endEntity.OnClosing += m_endEntity_OnClosing; } m_pathfindingHeuristic = this.Heuristic; m_terminationCriterion = this.Criterion; m_ignoredPrimitives = new HashSet <MyHighLevelPrimitive>(); IsValid = true; }
public MySmartGoal(IMyDestinationShape goal, MyEntity entity = null) { m_destination = goal; m_destinationCenter = goal.GetDestination(); m_endEntity = entity; if (m_endEntity != null) { m_destination.SetRelativeTransform(m_endEntity.PositionComp.WorldMatrixNormalizedInv); m_endEntity.OnClosing += m_endEntity_OnClosing; } m_pathfindingHeuristic = this.Heuristic; m_terminationCriterion = this.Criterion; m_ignoredPrimitives = new HashSet<MyHighLevelPrimitive>(); IsValid = true; }
public bool ReachableUnderThreshold(Vector3D begin, IMyDestinationShape end, float thresholdDistance) { this.m_reachPredicateDistance = thresholdDistance; MyNavigationPrimitive startingVertex = this.FindClosestPrimitive(begin, false, null); MyNavigationPrimitive primitive2 = this.FindClosestPrimitive(end.GetDestination(), false, null); if ((startingVertex != null) && (primitive2 != null)) { MyHighLevelPrimitive highLevelPrimitive = startingVertex.GetHighLevelPrimitive(); primitive2.GetHighLevelPrimitive(); if (new MySmartGoal(end, null).FindHighLevelPath(this, highLevelPrimitive) == null) { return(false); } this.m_reachEndPrimitive = primitive2; base.PrepareTraversal(startingVertex, null, new Predicate <MyNavigationPrimitive>(this.ReachablePredicate), null); try { using (MyPathFindingSystem <MyNavigationPrimitive> .Enumerator enumerator = base.GetEnumerator()) { while (true) { if (!enumerator.MoveNext()) { break; } if (enumerator.Current.Equals(this.m_reachEndPrimitive)) { return(true); } } } } finally { } } return(false); }
private bool TargetMoved() { return(Vector3D.DistanceSquared(m_destinationCenter, m_destination.GetDestination()) > 4.0f); }