public ForeachBuilder(ActionSet actionSet, IWorkshopTree array, bool recursive = false) { ActionSet = actionSet; IndexStore = actionSet.VarCollection.Assign("foreachIndex,", actionSet.IsGlobal, !recursive); Recursive = recursive; if (recursive) { RecursiveIndexReference recursiveStore = new RecursiveIndexReference(IndexStore); IndexStore = recursiveStore; actionSet.InitialSet().AddAction(recursiveStore.Reset()); actionSet.AddAction(recursiveStore.Push(0)); actionSet.ReturnHandler.AdditionalPopOnReturn.Add(recursiveStore); } else { actionSet.AddAction(IndexStore.SetVariable(0)); } Array = array; Condition = new V_Compare(IndexStore.GetVariable(), Operators.LessThan, Element.Part <V_CountOf>(Array)); Index = (Element)IndexStore.GetVariable(); IndexValue = Element.Part <V_ValueInArray>(Array, IndexStore.GetVariable()); actionSet.AddAction(Element.Part <A_While>(Condition)); }
public ForeachBuilder(ActionSet actionSet, IWorkshopTree array) : base(actionSet) { IndexStore = actionSet.VarCollection.Assign("foreachIndex,", actionSet.IsGlobal, true); Array = array; Condition = new V_Compare(IndexStore.GetVariable(), Operators.LessThan, Element.Part <V_CountOf>(Array)); Index = (Element)IndexStore.GetVariable(); IndexValue = Element.Part <V_ValueInArray>(Array, IndexStore.GetVariable()); }
private Element GetConnectedSegments(Element currentIndex) { Element currentSegmentCheck = new V_ArrayElement(); Element useAttribute; if (!reverseAttributes) { useAttribute = Element.TernaryConditional( new V_Compare(Node1(currentSegmentCheck), Operators.Equal, currentIndex), Node2Attribute(currentSegmentCheck), Node1Attribute(currentSegmentCheck) ); } else { useAttribute = Element.TernaryConditional( new V_Compare(Node1(currentSegmentCheck), Operators.Equal, currentIndex), Node1Attribute(currentSegmentCheck), Node2Attribute(currentSegmentCheck) ); } Element isValid; if (useAttributes) { isValid = Element.Part <V_ArrayContains>( Element.Part <V_Append>(attributes, new V_Number(0)), useAttribute ); } else { isValid = new V_Compare(useAttribute, Operators.Equal, new V_Number(0)); } return(Element.Part <V_FilteredArray>( Segments, Element.Part <V_And>( // Make sure one of the segments nodes is the current node. Element.Part <V_ArrayContains>( BothNodes(currentSegmentCheck), currentIndex ), isValid ) )); }
/// <summary>Returns true if the player takes longer than expected to reach the next node.</summary> public Element IsPathfindingStuck(Element player, Element scalar) { Element leniency = 2; Element defaultSpeed = 5.5; Element nodeDistance = DistanceToNextNode.Get(player); Element timeSinceLastNode = new V_TotalTimeElapsed() - TimeSinceLastNode.Get(player); Element isStuck = new V_Compare( nodeDistance - ((defaultSpeed * scalar * timeSinceLastNode) / leniency), Operators.LessThanOrEqual, new V_Number(0) ); return(Element.Part <V_And>(IsPathfinding(player), isStuck)); }
override protected MethodResult Get(PathfinderInfo info) { Element leniency = 2; Element player = (Element)Parameters[0]; Element scalar = (Element)Parameters[1]; Element defaultSpeed = 5.5; Element nodeDistance = info.DistanceToNext.GetVariable(player); Element timeSinceLastNode = new V_TotalTimeElapsed() - info.LastUpdate.GetVariable(player); Element isStuck = new V_Compare( nodeDistance - ((defaultSpeed * scalar * timeSinceLastNode) / leniency), Operators.LessThanOrEqual, 0 ); isStuck = Element.Part <V_And>(IsPathfinding.Get(info, player), isStuck); return(new MethodResult(null, isStuck)); }
public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues) { PathfinderInfo info = actionSet.Translate.DeltinScript.SetupPathfinder(); Element leniency = 2; Element player = (Element)parameterValues[0]; Element scalar = (Element)parameterValues[1]; Element defaultSpeed = 5.5; Element nodeDistance = (Element)info.DistanceToNext.GetVariable(player); Element timeSinceLastNode = new V_TotalTimeElapsed() - (Element)info.LastUpdate.GetVariable(player); Element isStuck = new V_Compare( nodeDistance - ((defaultSpeed * scalar * timeSinceLastNode) / leniency), Operators.LessThanOrEqual, new V_Number(0) ); return(Element.Part <V_And>(IsPathfinding.Get(info, player), isStuck)); }