public void Update(float g, float h, AStarNode parent, BasePathNode node) { this.G = g; this.H = h; this.Parent = parent; this.Node = node; }
public bool GetPathToClosestTurnableNode(BasePathNode start, Vector3 forward, ref List <BasePathNode> nodes) { float num = float.NegativeInfinity; BasePathNode basePathNode = null; foreach (BasePathNode item in start.linked) { float num2 = Vector3.Dot(forward, (item.transform.position - start.transform.position).normalized); if (num2 > num) { num = num2; basePathNode = item; } } if (basePathNode != null) { nodes.Add(basePathNode); if (!basePathNode.straightaway) { return(true); } return(GetPathToClosestTurnableNode(basePathNode, (basePathNode.transform.position - start.transform.position).normalized, ref nodes)); } return(false); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext; if (npcContext == null) { return; } if (npcContext.ReservedCoverPoint == null) { npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationCover, false, true, true, true); npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.CoverState, Rust.Ai.HTN.ScientistAStar.CoverState.None, true, true, true); } else { Vector3 position = npcContext.ReservedCoverPoint.Position; BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(position); if (Object.op_Inequality((Object)closestToPoint, (Object)null) && Object.op_Inequality((Object)((Component)closestToPoint).get_transform(), (Object)null)) { Vector3 vector3 = Vector3.op_Subtraction(((Component)closestToPoint).get_transform().get_position(), npcContext.BodyPosition); if ((double)((Vector3) ref vector3).get_sqrMagnitude() < 1.0) { npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationCover, true, true, true, true); npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.CoverState, npcContext.ReservedCoverPoint.NormalCoverType == CoverPoint.CoverType.Partial ? Rust.Ai.HTN.ScientistAStar.CoverState.Partial : Rust.Ai.HTN.ScientistAStar.CoverState.Full, true, true, true); return; } } npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationCover, false, true, true, true); npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.CoverState, Rust.Ai.HTN.ScientistAStar.CoverState.None, true, true, true); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext; if (npcContext == null) { return; } if (npcContext.ReservedCoverPoint == null) { npcContext.SetFact(Facts.AtLocationCover, false, true, true, true); npcContext.SetFact(Facts.CoverState, CoverState.None, true, true, true); return; } Vector3 position = npcContext.ReservedCoverPoint.Position; BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(position); if (!(closestToPoint != null) || !(closestToPoint.transform != null) || (closestToPoint.transform.position - npcContext.BodyPosition).sqrMagnitude >= 1f) { npcContext.SetFact(Facts.AtLocationCover, false, true, true, true); npcContext.SetFact(Facts.CoverState, CoverState.None, true, true, true); return; } npcContext.SetFact(Facts.AtLocationCover, true, true, true, true); npcContext.SetFact(Facts.CoverState, (npcContext.ReservedCoverPoint.NormalCoverType == CoverPoint.CoverType.Partial ? CoverState.Partial : CoverState.Full), true, true, true); }
public bool GetPathToClosestTurnableNode(BasePathNode start, Vector3 forward, ref List <BasePathNode> nodes) { Vector3 vector3; float single = Single.NegativeInfinity; BasePathNode basePathNode = null; foreach (BasePathNode basePathNode1 in start.linked) { vector3 = basePathNode1.transform.position - start.transform.position; float single1 = Vector3.Dot(forward, vector3.normalized); if (single1 <= single) { continue; } single = single1; basePathNode = basePathNode1; } if (basePathNode == null) { return(false); } nodes.Add(basePathNode); if (!basePathNode.straightaway) { return(true); } vector3 = basePathNode.transform.position - start.transform.position; return(this.GetPathToClosestTurnableNode(basePathNode, vector3.normalized, ref nodes)); }
public bool Contains(BasePathNode n) { for (int index = 0; index < this.Count; ++index) { AStarNode astarNode = this[index]; if (astarNode != null && ((object)astarNode.Node).Equals((object)n)) { return(true); } } return(false); }
public AStarNode GetAStarNodeOf(BasePathNode n) { for (int index = 0; index < this.Count; ++index) { AStarNode astarNode = this[index]; if (astarNode != null && ((object)astarNode.Node).Equals((object)n)) { return(astarNode); } } return((AStarNode)null); }
public bool Contains(BasePathNode n) { for (int i = 0; i < base.Count; i++) { AStarNode item = base[i]; if (item != null && item.Node.Equals(n)) { return(true); } } return(false); }
public AStarNode GetAStarNodeOf(BasePathNode n) { for (int i = 0; i < base.Count; i++) { AStarNode item = base[i]; if (item != null && item.Node.Equals(n)) { return(item); } } return(null); }
public bool GetEngagementPath(ref List <BasePathNode> nodes) { BasePathNode closestToPoint = patrolPath.GetClosestToPoint(base.transform.position); Vector3 normalized = (closestToPoint.transform.position - base.transform.position).normalized; if (Vector3.Dot(base.transform.forward, normalized) > 0f) { nodes.Add(closestToPoint); if (!closestToPoint.straightaway) { return(true); } } return(GetPathToClosestTurnableNode(closestToPoint, base.transform.forward, ref nodes)); }
public void UpdateForNode(BasePathNode node) { if (!Nodes.Contains(node)) { return; } Box.Minimum = Vector3.Min(Box.Minimum, node.Position); Box.Maximum = Vector3.Max(Box.Maximum, node.Position); if (Node1 != null) { Node1.UpdateForNode(node); } if (Node2 != null) { Node2.UpdateForNode(node); } }
public BasePathNode GetClosestToPoint(Vector3 point) { BasePathNode result = nodes[0]; float num = float.PositiveInfinity; foreach (BasePathNode node in nodes) { if (!(node == null) && !(node.transform == null)) { float sqrMagnitude = (point - node.transform.position).sqrMagnitude; if (sqrMagnitude < num) { num = sqrMagnitude; result = node; } } } return(result); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext; if (npcContext == null) { return; } if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player != null) { Vector3 destination = ScientistAStarDomain.AStarNavigateToLastKnownLocationOfPrimaryEnemyPlayer.GetDestination(npcContext); BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(destination); if (closestToPoint != null && closestToPoint.transform != null && (closestToPoint.transform.position - npcContext.BodyPosition).sqrMagnitude < 1f) { npcContext.SetFact(Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 1, true, true, true); return; } } npcContext.SetFact(Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 0, true, true, true); }
public BasePathNode GetClosestToPoint(Vector3 point) { BasePathNode basePathNode = this.nodes[0]; float num = float.PositiveInfinity; foreach (BasePathNode node in this.nodes) { if (!Object.op_Equality((Object)node, (Object)null) && !Object.op_Equality((Object)((Component)node).get_transform(), (Object)null)) { Vector3 vector3 = Vector3.op_Subtraction(point, ((Component)node).get_transform().get_position()); float sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude(); if ((double)sqrMagnitude < (double)num) { num = sqrMagnitude; basePathNode = node; } } } return(basePathNode); }
public bool SetDestination(BasePath path, BasePathNode newTargetNode, float speedFraction) { if (!AI.move) { return(false); } if (!AI.navthink) { return(false); } paused = false; if (!CanUseAStar) { return(false); } if (newTargetNode == targetNode && HasPath) { return(true); } if (ReachedPosition(newTargetNode.transform.position)) { return(true); } BasePathNode closestToPoint = path.GetClosestToPoint(base.transform.position); if (closestToPoint == null || closestToPoint.transform == null) { return(false); } float pathCost; if (AStarPath.FindPath(closestToPoint, newTargetNode, out currentAStarPath, out pathCost)) { currentSpeedFraction = speedFraction; targetNode = newTargetNode; SetCurrentNavigationType(NavigationType.AStar); Destination = newTargetNode.transform.position; return(true); } return(false); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext; if (npcContext == null) { return; } if ((npcContext.BodyPosition - npcContext.Domain.SpawnPosition).sqrMagnitude < 3f) { npcContext.SetFact(Facts.AtLocationHome, true, true, true, true); return; } BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(npcContext.Domain.SpawnPosition); if (closestToPoint != null && closestToPoint.transform != null && (npcContext.BodyPosition - closestToPoint.transform.position).sqrMagnitude < 3f) { npcContext.SetFact(Facts.AtLocationHome, true, true, true, true); } npcContext.SetFact(Facts.AtLocationHome, false, true, true, true); }
public BasePathNode GetClosestToPoint(Vector3 point) { BasePathNode item = this.nodes[0]; float single = Single.PositiveInfinity; foreach (BasePathNode node in this.nodes) { if (node == null || node.transform == null) { continue; } float single1 = (point - node.transform.position).sqrMagnitude; if (single1 >= single) { continue; } single = single1; item = node; } return(item); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistAStarContext npcContext = npc.AiDomain.NpcContext as ScientistAStarContext; if (npcContext == null) { return; } if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null)) { Vector3 destination = ScientistAStarDomain.AStarNavigateToLastKnownLocationOfPrimaryEnemyPlayer.GetDestination(npcContext); BasePathNode closestToPoint = npcContext.Domain.Path.GetClosestToPoint(destination); if (Object.op_Inequality((Object)closestToPoint, (Object)null) && Object.op_Inequality((Object)((Component)closestToPoint).get_transform(), (Object)null)) { Vector3 vector3 = Vector3.op_Subtraction(((Component)closestToPoint).get_transform().get_position(), npcContext.BodyPosition); if ((double)((Vector3) ref vector3).get_sqrMagnitude() < 1.0) { npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 1, true, true, true); return; } } } npcContext.SetFact(Rust.Ai.HTN.ScientistAStar.Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 0, true, true, true); }
public void UpdateMovement_Hunt() { float single; if (Interface.CallHook("OnBradleyApcHunt", this) != null) { return; } if (this.patrolPath == null) { return; } BradleyAPC.TargetInfo item = this.targetList[0]; if (item.IsValid()) { if (this.HasPath() && item.IsVisible()) { if (this.currentPath.Count > 1) { Vector3 vector3 = this.currentPath[this.currentPathIndex]; this.ClearPath(); this.currentPath.Add(vector3); this.finalDestination = vector3; this.currentPathIndex = 0; return; } } else if (UnityEngine.Time.time > this.nextEngagementPathTime && !this.HasPath() && !item.IsVisible()) { bool flag = false; BasePathNode closestToPoint = this.patrolPath.GetClosestToPoint(base.transform.position); List <BasePathNode> list = Facepunch.Pool.GetList <BasePathNode>(); if (this.GetEngagementPath(ref list)) { flag = true; closestToPoint = list[list.Count - 1]; } BasePathNode basePathNode = null; List <BasePathNode> basePathNodes = Facepunch.Pool.GetList <BasePathNode>(); this.patrolPath.GetNodesNear(item.lastSeenPosition, ref basePathNodes, 30f); Stack <BasePathNode> basePathNodes1 = null; float single1 = Single.PositiveInfinity; float single2 = this.mainTurretEyePos.localPosition.y; foreach (BasePathNode basePathNode1 in basePathNodes) { Stack <BasePathNode> basePathNodes2 = new Stack <BasePathNode>(); if (!item.entity.IsVisible(basePathNode1.transform.position + new Vector3(0f, single2, 0f), Single.PositiveInfinity) || !AStarPath.FindPath(closestToPoint, basePathNode1, out basePathNodes2, out single) || single >= single1) { continue; } basePathNodes1 = basePathNodes2; single1 = single; basePathNode = basePathNode1; } if (basePathNodes1 != null) { this.currentPath.Clear(); if (flag) { for (int i = 0; i < list.Count - 1; i++) { this.currentPath.Add(list[i].transform.position); } } foreach (BasePathNode basePathNode2 in basePathNodes1) { this.currentPath.Add(basePathNode2.transform.position); } this.currentPathIndex = -1; this.pathLooping = false; this.finalDestination = basePathNode.transform.position; } Facepunch.Pool.FreeList <BasePathNode>(ref basePathNodes); Facepunch.Pool.FreeList <BasePathNode>(ref list); this.nextEngagementPathTime = UnityEngine.Time.time + 5f; } } }
public static bool FindPath( BasePathNode start, BasePathNode goal, out Stack <BasePathNode> path, out float pathCost) { path = (Stack <BasePathNode>)null; pathCost = -1f; bool flag = false; if (Object.op_Equality((Object)start, (Object)goal)) { return(false); } AStarNodeList astarNodeList = new AStarNodeList(); HashSet <BasePathNode> basePathNodeSet = new HashSet <BasePathNode>(); AStarNode astarNode1 = new AStarNode(0.0f, AStarPath.Heuristic(start, goal), (AStarNode)null, start); astarNodeList.Add(astarNode1); while (astarNodeList.Count > 0) { AStarNode parent = astarNodeList[0]; astarNodeList.RemoveAt(0); basePathNodeSet.Add(parent.Node); if (parent.Satisfies(goal)) { path = new Stack <BasePathNode>(); pathCost = 0.0f; for (; parent.Parent != null; parent = parent.Parent) { pathCost += parent.F; path.Push(parent.Node); } if (parent != null) { path.Push(parent.Node); } flag = true; break; } foreach (BasePathNode basePathNode in parent.Node.linked) { if (!basePathNodeSet.Contains(basePathNode)) { float g = parent.G + AStarPath.Heuristic(parent.Node, basePathNode); AStarNode astarNodeOf = astarNodeList.GetAStarNodeOf(basePathNode); if (astarNodeOf == null) { AStarNode astarNode2 = new AStarNode(g, AStarPath.Heuristic(basePathNode, goal), parent, basePathNode); astarNodeList.Add(astarNode2); astarNodeList.AStarNodeSort(); } else if ((double)g < (double)astarNodeOf.G) { astarNodeOf.Update(g, astarNodeOf.H, parent, basePathNode); astarNodeList.AStarNodeSort(); } } } } return(flag); }
private static float Heuristic(BasePathNode from, BasePathNode to) { return(Vector3.Distance(from.transform.position, to.transform.position)); }
private void StopAStar() { currentAStarPath = null; targetNode = null; }
public bool Satisfies(BasePathNode node) { return(this.Node == node); }
public void UpdateMovement_Hunt() { if (Interface.CallHook("OnBradleyApcHunt", this) != null || patrolPath == null) { return; } TargetInfo targetInfo = targetList[0]; if (!targetInfo.IsValid()) { return; } if (HasPath() && targetInfo.IsVisible()) { if (currentPath.Count > 1) { Vector3 item = currentPath[currentPathIndex]; ClearPath(); currentPath.Add(item); finalDestination = item; currentPathIndex = 0; } } else { if (!(UnityEngine.Time.time > nextEngagementPathTime) || HasPath() || targetInfo.IsVisible()) { return; } bool flag = false; BasePathNode start = patrolPath.GetClosestToPoint(base.transform.position); List <BasePathNode> nodes = Facepunch.Pool.GetList <BasePathNode>(); if (GetEngagementPath(ref nodes)) { flag = true; start = nodes[nodes.Count - 1]; } BasePathNode basePathNode = null; List <BasePathNode> nearNodes = Facepunch.Pool.GetList <BasePathNode>(); patrolPath.GetNodesNear(targetInfo.lastSeenPosition, ref nearNodes, 30f); Stack <BasePathNode> stack = null; float num = float.PositiveInfinity; float y = mainTurretEyePos.localPosition.y; foreach (BasePathNode item2 in nearNodes) { Stack <BasePathNode> path = new Stack <BasePathNode>(); float pathCost; if (targetInfo.entity.IsVisible(item2.transform.position + new Vector3(0f, y, 0f)) && AStarPath.FindPath(start, item2, out path, out pathCost) && pathCost < num) { stack = path; num = pathCost; basePathNode = item2; } } if (stack == null && nearNodes.Count > 0) { Stack <BasePathNode> path2 = new Stack <BasePathNode>(); BasePathNode basePathNode2 = nearNodes[UnityEngine.Random.Range(0, nearNodes.Count)]; float pathCost2; if (AStarPath.FindPath(start, basePathNode2, out path2, out pathCost2) && pathCost2 < num) { stack = path2; basePathNode = basePathNode2; } } if (stack != null) { currentPath.Clear(); if (flag) { for (int i = 0; i < nodes.Count - 1; i++) { currentPath.Add(nodes[i].transform.position); } } foreach (BasePathNode item3 in stack) { currentPath.Add(item3.transform.position); } currentPathIndex = -1; pathLooping = false; finalDestination = basePathNode.transform.position; } Facepunch.Pool.FreeList(ref nearNodes); Facepunch.Pool.FreeList(ref nodes); nextEngagementPathTime = UnityEngine.Time.time + 5f; } }
public void UpdateMovement_Patrol() { float single; Stack <BasePathNode> basePathNodes; if (this.patrolPath == null) { return; } if (UnityEngine.Time.time < this.nextPatrolTime) { return; } this.nextPatrolTime = UnityEngine.Time.time + 20f; if (this.HasPath() && !this.IsAtFinalDestination()) { return; } if (Interface.CallHook("OnBradleyApcPatrol", this) != null) { return; } PathInterestNode randomInterestNodeAwayFrom = this.patrolPath.GetRandomInterestNodeAwayFrom(base.transform.position, 10f); BasePathNode closestToPoint = this.patrolPath.GetClosestToPoint(randomInterestNodeAwayFrom.transform.position); BasePathNode item = null; bool flag = false; List <BasePathNode> list = Facepunch.Pool.GetList <BasePathNode>(); if (!this.GetEngagementPath(ref list)) { item = this.patrolPath.GetClosestToPoint(base.transform.position); } else { flag = true; item = list[list.Count - 1]; } if (Vector3.Distance(this.finalDestination, closestToPoint.transform.position) > 2f) { if (closestToPoint == item) { this.currentPath.Clear(); this.currentPath.Add(closestToPoint.transform.position); this.currentPathIndex = -1; this.pathLooping = false; this.finalDestination = closestToPoint.transform.position; return; } if (AStarPath.FindPath(item, closestToPoint, out basePathNodes, out single)) { this.currentPath.Clear(); if (flag) { for (int i = 0; i < list.Count - 1; i++) { this.currentPath.Add(list[i].transform.position); } } foreach (BasePathNode basePathNode in basePathNodes) { this.currentPath.Add(basePathNode.transform.position); } this.currentPathIndex = -1; this.pathLooping = false; this.finalDestination = closestToPoint.transform.position; } } }
public bool Satisfies(BasePathNode node) { return(Object.op_Equality((Object)this.Node, (Object)node)); }
private static float Heuristic(BasePathNode from, BasePathNode to) { return(Vector3.Distance(((Component)from).get_transform().get_position(), ((Component)to).get_transform().get_position())); }
public static bool FindPath(BasePathNode start, BasePathNode goal, out Stack <BasePathNode> path, out float pathCost) { path = null; pathCost = -1f; bool flag = false; if (start == goal) { return(false); } AStarNodeList aStarNodeList = new AStarNodeList(); HashSet <BasePathNode> basePathNodes = new HashSet <BasePathNode>(); AStarNode aStarNode = new AStarNode(0f, AStarPath.Heuristic(start, goal), null, start); aStarNodeList.Add(aStarNode); while (aStarNodeList.Count > 0) { AStarNode item = aStarNodeList[0]; aStarNodeList.RemoveAt(0); basePathNodes.Add(item.Node); if (!item.Satisfies(goal)) { foreach (BasePathNode node in item.Node.linked) { if (basePathNodes.Contains(node)) { continue; } float g = item.G + AStarPath.Heuristic(item.Node, node); AStarNode aStarNodeOf = aStarNodeList.GetAStarNodeOf(node); if (aStarNodeOf != null) { if (g >= aStarNodeOf.G) { continue; } aStarNodeOf.Update(g, aStarNodeOf.H, item, node); aStarNodeList.AStarNodeSort(); } else { aStarNodeOf = new AStarNode(g, AStarPath.Heuristic(node, goal), item, node); aStarNodeList.Add(aStarNodeOf); aStarNodeList.AStarNodeSort(); } } } else { path = new Stack <BasePathNode>(); pathCost = 0f; while (item.Parent != null) { pathCost += item.F; path.Push(item.Node); item = item.Parent; } if (item != null) { path.Push(item.Node); } flag = true; break; } } return(flag); }
public void UpdateMovement_Patrol() { if (patrolPath == null || UnityEngine.Time.time < nextPatrolTime) { return; } nextPatrolTime = UnityEngine.Time.time + 20f; if ((HasPath() && !IsAtFinalDestination()) || Interface.CallHook("OnBradleyApcPatrol", this) != null) { return; } PathInterestNode randomInterestNodeAwayFrom = patrolPath.GetRandomInterestNodeAwayFrom(base.transform.position); BasePathNode closestToPoint = patrolPath.GetClosestToPoint(randomInterestNodeAwayFrom.transform.position); BasePathNode basePathNode = null; bool flag = false; List <BasePathNode> nodes = Facepunch.Pool.GetList <BasePathNode>(); if (GetEngagementPath(ref nodes)) { flag = true; basePathNode = nodes[nodes.Count - 1]; } else { basePathNode = patrolPath.GetClosestToPoint(base.transform.position); } if (!(Vector3.Distance(finalDestination, closestToPoint.transform.position) > 2f)) { return; } if (closestToPoint == basePathNode) { currentPath.Clear(); currentPath.Add(closestToPoint.transform.position); currentPathIndex = -1; pathLooping = false; finalDestination = closestToPoint.transform.position; } else { Stack <BasePathNode> path; float pathCost; if (!AStarPath.FindPath(basePathNode, closestToPoint, out path, out pathCost)) { return; } currentPath.Clear(); if (flag) { for (int i = 0; i < nodes.Count - 1; i++) { currentPath.Add(nodes[i].transform.position); } } foreach (BasePathNode item in path) { currentPath.Add(item.transform.position); } currentPathIndex = -1; pathLooping = false; finalDestination = closestToPoint.transform.position; } }