/// <summary>Looks at a player's future segments.</summary> public Element IsTravelingToSegment(ActionSet actionSet, Element targetPlayer, Element segment) { IndexReference result = actionSet.VarCollection.Assign("Lookahead: Result", actionSet.IsGlobal, true); actionSet.AddAction(result.SetVariable(new V_False())); IndexReference look = actionSet.VarCollection.Assign("Pathfind: Lookahead", actionSet.IsGlobal, true); actionSet.AddAction(look.SetVariable(Current.Get(targetPlayer))); // Get the path. actionSet.AddAction(Element.Part <A_While>(Element.Part <V_And>(new V_Compare( ParentArray.Get(targetPlayer)[look.Get()] - 1, Operators.GreaterThanOrEqual, new V_Number(0) ), !result.Get()))); Element currentNode = PathmapInstance.Nodes.Get()[PathmapReference.Get(targetPlayer)][look.Get()]; Element nextNode = PathmapInstance.Nodes.Get()[PathmapReference.Get(targetPlayer)][ParentArray.Get(targetPlayer)[look.Get()] - 1]; actionSet.AddAction(result.SetVariable(new V_Compare( segment, Operators.Equal, Element.Part <V_FirstOf>(PathmapInstance.SegmentsFromNodes(PathmapReference.Get(targetPlayer), look.Get(), ParentArray.Get(targetPlayer)[look.Get()] - 1)) ))); actionSet.AddAction(look.SetVariable(ParentArray.Get(targetPlayer)[look.Get()] - 1)); actionSet.AddAction(new A_End()); return(result.Get()); }
/// <summary>Starts pathfinding for the specified players/</summary> /// <param name="actionSet">The actionset of the current rule.</param> /// <param name="players">The players that will start pathfinding.</param> /// <param name="pathmapReference">A reference to the pathmap the players are pathfinding with.</param> /// <param name="parentArray">The parent array path.</param> /// <param name="attributeArray">The path attributes.</param> /// <param name="destination">The destination the players are navigating to.</param> public void Pathfind(ActionSet actionSet, Element players, Element pathmapReference, Element parentArray, Element attributeArray, Element destination) { // Set target's pathmap reference. actionSet.AddAction(PathmapReference.SetVariable( value: pathmapReference, targetPlayer: players )); // Set target's parent array. actionSet.AddAction(ParentArray.SetVariable( value: parentArray, targetPlayer: players )); // Set target's attribute array. actionSet.AddAction(AttributeArray.SetVariable( value: attributeArray, targetPlayer: players )); // Set target's destination. actionSet.AddAction(Destination.SetVariable( value: destination, targetPlayer: players )); // For each of the players, get the current. SetCurrent(actionSet, players); }
Element PositionAtOrDestination(Element node, Element player = null) => Element.TernaryConditional( // Current will be -1 if the player reached the last node. Element.Compare(node, Operator.Equal, Element.Num(-1)), // If so, go to the destination. Destination.GetVariable(player), // Otherwise, go to the current node. PathmapInstance.Nodes.Get(_toWorkshop, PathmapReference.Get(player))[node] );
/// <summary>Stops pathfinding for the players that are pathfinding using the specified pathmap reference.</summary> /// <param name="actionSet">The actionset of the current rule.</param> /// <param name="pathmapReference">The reference of the pathmap. Any players using this pathmap will stop pathfinding.</param> /// <param name="players">The players to stop pathfinding for.</param> public void StopPathfindingWithPathmap(ActionSet actionSet, Element pathmapReference, Element players) => StopPathfinding( actionSet, // Filter players by whos pathfinding reference is equal to pathmapReference. Element.Part <V_FilteredArray>( players, new V_Compare( PathmapReference.GetVariable(new V_ArrayElement()), Operators.Equal, pathmapReference ) ) );
/// <summary>Stops pathfinding for the players that are pathfinding using the specified pathmap reference.</summary> /// <param name="actionSet">The actionset of the current rule.</param> /// <param name="pathmapReference">The reference of the pathmap. Any players using this pathmap will stop pathfinding.</param> /// <param name="players">The players to stop pathfinding for.</param> public void StopPathfindingWithPathmap(ActionSet actionSet, Element pathmapReference, Element players) => StopPathfinding( actionSet, // Filter players by whos pathfinding reference is equal to pathmapReference. Element.Filter( players, Element.Compare( PathmapReference.GetVariable(Element.ArrayElement()), Operator.Equal, pathmapReference ) ) );
/// <summary>Gets the next pathfinding attribute.</summary> // public Element NextSegmentAttribute(Element player) => Element.TernaryConditional( // Element.Part<V_And>(IsPathfinding(player), new V_Compare(Current.GetVariable(player), Operators.NotEqual, new V_Number(-1))), // AttributeArray.Get(player)[Current.Get(player)], // new V_Number(-1) // ); public Element NextSegmentAttribute(Element player) => Element.Part <V_MappedArray>(Element.Part <V_FilteredArray>( PathmapInstance.Attributes.Get()[PathmapReference.Get(player)], Element.Part <V_And>( new V_Compare(Element.Part <V_XOf>(Element.Part <V_ArrayElement>()), Operators.Equal, Current.Get(player)), new V_Compare(Element.Part <V_YOf>(Element.Part <V_ArrayElement>()), Operators.Equal, ParentArray.Get()[Current.Get()] - 1) ) ), Element.Part <V_ZOf>(Element.Part <V_ArrayElement>()));
/// <summary>The position of the current node the player is walking towards.</summary> public Element CurrentPosition(Element player = null) => PathmapInstance.Nodes.Get()[PathmapReference.Get()][Current.Get(player)];
/// <summary>Gets the closest node from a position.</summary> public Element ClosestNode(ActionSet actionSet, Element position) { // Get the nodes in the pathmap Element nodes = Element.Part <V_ValueInArray>(PathmapInstance.Nodes.GetVariable(), PathmapReference.GetVariable()); // Get the closest node index. if (ApplicableNodeDeterminer == null) { return(DijkstraBase.ClosestNodeToPosition(nodes, position, PotentiallyNullNodes)); } else { return((Element)ApplicableNodeDeterminer.Invoke(actionSet, nodes, position)); } }
Element GetNextSegmentAttribute(Element player) => Element.Map(Element.Filter( PathmapInstance.Attributes.Get(_toWorkshop, PathmapReference.Get(player)), Element.And( Element.Compare(Element.XOf(Element.ArrayElement()), Operator.Equal, ParentArray.Get(player)[Current.Get(player)] - 1), Element.Compare(Element.YOf(Element.ArrayElement()), Operator.Equal, ParentArray.Get(player)[ParentArray.Get(player)[Current.Get(player)] - 1] - 1) ) ), Element.ZOf(Element.ArrayElement()));
/// <summary>Gets the closest node from a position.</summary> public Element ClosestNode(ActionSet actionSet, Element position) => PathmapInstance.GetNodeFromPositionHandler(actionSet, PathmapReference.Get()).NodeFromPosition(position);