protected override void New(ActionSet actionSet, NewClassInfo newClassInfo)
        {
            Element index = (Element)newClassInfo.ObjectReference.GetVariable();

            if (newClassInfo.AdditionalParameterData.Length > 0)
            {
                // Get the pathmap data.
                PathMap pathMap = (PathMap)newClassInfo.AdditionalParameterData[0];

                IndexReference nodes    = actionSet.VarCollection.Assign("_tempNodes", actionSet.IsGlobal, false);
                IndexReference segments = actionSet.VarCollection.Assign("_tempSegments", actionSet.IsGlobal, false);

                actionSet.AddAction(nodes.SetVariable(new V_EmptyArray()));
                actionSet.AddAction(segments.SetVariable(new V_EmptyArray()));

                foreach (var node in pathMap.Nodes)
                {
                    actionSet.AddAction(nodes.ModifyVariable(operation: Operation.AppendToArray, value: node.ToVector()));
                }
                foreach (var segment in pathMap.Segments)
                {
                    actionSet.AddAction(segments.ModifyVariable(operation: Operation.AppendToArray, value: segment.AsWorkshopData()));
                }

                actionSet.AddAction(Nodes.SetVariable((Element)nodes.GetVariable(), index: index));
                actionSet.AddAction(Segments.SetVariable((Element)segments.GetVariable(), index: index));
            }
            else
            {
                actionSet.AddAction(Nodes.SetVariable(new V_EmptyArray(), index: index));
                actionSet.AddAction(Segments.SetVariable(new V_EmptyArray(), index: index));
            }
        }
Ejemplo n.º 2
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            if (parameterValues[0] is V_Number n)
            {
                V_Number[] indexes = new V_Number[n.Value < 0 ? 0 : (int)n.Value];
                for (int i = 0; i < indexes.Length; i++)
                {
                    indexes[i] = new V_Number(i);
                }
                return(Element.CreateArray(indexes));
            }
            else
            {
                IndexReference array  = actionSet.VarCollection.Assign("_foreachArrayBuilder", actionSet.IsGlobal, false);
                IndexReference length = actionSet.VarCollection.Assign("_foreachArrayBuilderLength", actionSet.IsGlobal, true);
                IndexReference i      = actionSet.VarCollection.Assign("_foreachArrayBuilderIndex", actionSet.IsGlobal, true);

                actionSet.AddAction(ArrayBuilder <Element> .Build(
                                        length.SetVariable((Element)parameterValues[0]),
                                        array.SetVariable(new V_EmptyArray()),
                                        i.SetVariable(0),
                                        Element.Part <A_While>((Element)i.GetVariable() < (Element)length.GetVariable()),
                                        array.SetVariable((Element)i.GetVariable(), null, (Element)i.GetVariable()),
                                        i.ModifyVariable(Operation.Add, 1),
                                        new A_End()
                                        ));

                return(array.GetVariable());
            }
        }
        public Element Get(ResolveInfoComponent resolveInfo, ActionSet actionSet, Element target)
        {
            ActionSet       = actionSet;
            ResolveInfo     = resolveInfo;
            Target          = target;
            PathmapInstance = actionSet.DeltinScript.GetComponent <PathfinderTypesComponent>().Pathmap;

            // Lookahead status
            IndexReference result = actionSet.VarCollection.Assign("Lookahead: Result", actionSet.IsGlobal, true);

            actionSet.AddAction(result.SetVariable(Element.False()));

            // The lookhead controller
            Look = actionSet.VarCollection.Assign("Pathfind: Lookahead", actionSet.IsGlobal, true);
            actionSet.AddAction(Look.SetVariable(resolveInfo.Current.Get(target)));

            // The loop
            actionSet.AddAction(Element.While(Element.And(
                                                  !result.Get(),
                                                  LoopCondition()
                                                  )));

            // Set the result.
            actionSet.AddAction(result.SetVariable(SetResult()));

            // End
            actionSet.AddAction(Look.SetVariable(Next));
            actionSet.AddAction(Element.End());
            return(result.Get());
        }
Ejemplo n.º 4
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            // Setup the continue skip.
            ContinueSkip continueSkip = actionSet.ContinueSkip;

            continueSkip.Setup(actionSet);

            IndexReference result = actionSet.VarCollection.Assign($"_conditionTestResult", actionSet.IsGlobal, true);

            continueSkip.SetSkipCount(actionSet, continueSkip.GetSkipCount(actionSet) + 3);
            actionSet.AddAction(ArrayBuilder <Element> .Build(
                                    // This will continue at (0) if the rule loops.
                                    new A_LoopIfConditionIsFalse(),
                                    // Set the result to true.
                                    result.SetVariable(new V_True()),
                                    Element.Part <A_Skip>(new V_Number(1)),

                                    // The rule will loop back here (0) if false.
                                    result.SetVariable(new V_False())
                                    ));
            continueSkip.ResetSkipCount(actionSet);

            if (TestingIfTrue)
            {
                return(result.GetVariable());
            }
            else
            {
                return(Element.Part <V_Not>(result.GetVariable()));
            }
        }
        /// <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());
        }
        public void EndRecursiveLoop()
        {
            // Pop the object store array.
            if (_builder.Controller.Attributes.IsInstance)
            {
                actionSet.AddAction(_objectStore.ModifyVariable(Operation.RemoveFromArrayByIndex, Element.CountOf(_objectStore.GetVariable()) - 1));
            }

            // Pop the parameters.
            _builder.ParameterHandler.Pop(_builder.ActionSet);

            // Restart the method from the specified position if there are any elements in the continue array.
            actionSet.AddAction(Element.SkipIf(Element.Compare(
                                                   Element.CountOf(_continueArray.GetVariable()),
                                                   Operator.Equal,
                                                   Element.Num(0)
                                                   ), Element.Num(3)));

            // Store the next continue and pop the continue array.
            actionSet.AddAction(_nextContinue.SetVariable(Element.LastOf(_continueArray.GetVariable())));
            actionSet.AddAction(_continueArray.ModifyVariable(Operation.RemoveFromArrayByIndex, Element.CountOf(_continueArray.GetVariable()) - 1));

            // Mark the end of the method.
            actionSet.AddAction(_endOfMethod);
            actionSet.AddAction(Element.End());

            // Reset nextContinue.
            actionSet.AddAction(_nextContinue.SetVariable(0));
        }
Ejemplo n.º 7
0
        protected override void GetResult()
        {
            /*
             |  |
             +--+--+--+
             |
             */

            IndexReference newParentArray = actionSet.VarCollection.Assign("Pathfinder: New parent array", actionSet.IsGlobal, false);

            // Flip the parent array.
            IndexReference backTracker = actionSet.VarCollection.Assign("Pathfinder: Backtracker", actionSet.IsGlobal, assignExtended);

            actionSet.AddAction(backTracker.SetVariable(current.Get()));

            // Get the path.
            actionSet.AddAction(Element.Part <A_While>(new V_Compare(
                                                           backTracker.GetVariable(),
                                                           Operators.GreaterThanOrEqual,
                                                           new V_Number(0)
                                                           )));

            Element next = parentArray.Get()[backTracker.Get()] - 1;

            actionSet.AddAction(newParentArray.SetVariable(index: next, value: backTracker.Get() + 1));

            actionSet.AddAction(backTracker.SetVariable(next));
            actionSet.AddAction(A_Wait.MinimumWait); // TODO: Should there be a minwait here?
            actionSet.AddAction(new A_End());

            actionSet.AddAction(parentArray.SetVariable(newParentArray.Get()));

            resolveInfo.Pathfind(actionSet, player, pathmapObject, parentArray.Get(), parentAttributeInfo.Get(), Nodes[current.Get()]);
        }
Ejemplo n.º 8
0
        public Element Get(ResolveInfoComponent resolveInfo, ActionSet actionSet, Element target)
        {
            ActionSet       = actionSet;
            ResolveInfo     = resolveInfo;
            Target          = target;
            PathmapInstance = actionSet.Translate.DeltinScript.Types.GetInstance <PathmapClass>();

            // Lookahead status
            IndexReference result = actionSet.VarCollection.Assign("Lookahead: Result", actionSet.IsGlobal, true);

            actionSet.AddAction(result.SetVariable(new V_False()));

            // The lookhead controller
            Look = actionSet.VarCollection.Assign("Pathfind: Lookahead", actionSet.IsGlobal, true);
            actionSet.AddAction(Look.SetVariable(resolveInfo.Current.Get(target)));

            // The loop
            actionSet.AddAction(Element.Part <A_While>(Element.Part <V_And>(
                                                           !result.Get(),
                                                           LoopCondition()
                                                           )));

            // Set the result.
            actionSet.AddAction(result.SetVariable(SetResult()));

            // End
            actionSet.AddAction(Look.SetVariable(Next));
            actionSet.AddAction(new A_End());
            return(result.Get());
        }
        private Element FirstNullOrLength(ActionSet actionSet, Element array, string tempVariableName)
        {
            // Get the index of the first null node.
            IndexReference index = actionSet.VarCollection.Assign(tempVariableName, actionSet.IsGlobal, true);

            // Get the first null value.
            index.SetVariable(Element.Part <V_IndexOfArrayValue>(array, new V_Null()));

            // If the index is -1, use the count of the element.
            index.SetVariable(Element.TernaryConditional(new V_Compare(index.Get(), Operators.Equal, new V_Number(-1)), Element.Part <V_CountOf>(array), index.Get()));

            // Done
            return(index.Get());
        }
        private static Element ContainParameter(ActionSet actionSet, string name, IWorkshopTree value)
        {
            IndexReference containParameter = actionSet.VarCollection.Assign(name, actionSet.IsGlobal, true);

            actionSet.AddAction(containParameter.SetVariable((Element)value));
            return((Element)containParameter.GetVariable());
        }
        override protected void Assign()
        {
            closestNodesToPlayers = actionSet.VarCollection.Assign("Dijkstra: Closest nodes", actionSet.IsGlobal, false);
            actionSet.AddAction(closestNodesToPlayers.SetVariable(Element.Part <V_EmptyArray>()));

            ForeachBuilder getClosestNodes = new ForeachBuilder(actionSet, players);

            actionSet.AddAction(closestNodesToPlayers.SetVariable(
                                    Element.Part <V_Append>(
                                        closestNodesToPlayers.GetVariable(),
                                        ClosestNodeToPosition(Nodes, getClosestNodes.IndexValue)
                                        )
                                    ));

            getClosestNodes.Finish();
        }
        // IComponent
        public void Init(DeltinScript deltinScript)
        {
            DeltinScript = deltinScript;

            _waitAsyncQueue = DeltinScript.VarCollection.Assign("waitAsync_queue", true, false);
            DeltinScript.InitialGlobal.ActionSet.AddAction(_waitAsyncQueue.SetVariable(Element.EmptyArray()));

            // Rule creator.
            var rule = new TranslateRule(DeltinScript, "waitAsync", RuleEvent.OngoingGlobal);

            rule.Conditions.Add(new Condition(
                                    Element.Any(_waitAsyncQueue.Get(), ArrayElementTimeSurpassed(Element.ArrayElement()))
                                    ));

            // Get the affected item.
            var item = DeltinScript.VarCollection.Assign("waitAsync_item", true, false);

            rule.ActionSet.AddAction(item.SetVariable(Element.FirstOf(Element.Filter(
                                                                          Element.Map(_waitAsyncQueue.Get(), Element.ArrayIndex()),
                                                                          ArrayElementTimeSurpassed(_waitAsyncQueue.Get()[Element.ArrayElement()])
                                                                          ))));

            // Activate item lambda.
            DeltinScript.WorkshopConverter.LambdaBuilder.Call(rule.ActionSet.New(Element.LastOf(_waitAsyncQueue.Get()[item.Get()])), new Functions.Builder.CallInfo(), null);

            // Remove from queue.
            rule.ActionSet.AddAction(_waitAsyncQueue.ModifyVariable(Operation.RemoveFromArrayByIndex, item.Get()));

            // Loop if another item needs to execute on the same tick.
            rule.ActionSet.AddAction(Element.LoopIfConditionIsTrue());

            // Get the rule.
            DeltinScript.WorkshopRules.Add(rule.GetRule());
        }
        // IComponent
        public void Init()
        {
            _waitAsyncQueue = DeltinScript.VarCollection.Assign("waitAsync_queue", true, false);
            DeltinScript.InitialGlobal.ActionSet.AddAction(_waitAsyncQueue.SetVariable(new V_EmptyArray()));

            // Rule creator.
            var rule = new TranslateRule(DeltinScript, "waitAsync", RuleEvent.OngoingGlobal);

            rule.Conditions.Add(new Condition(
                                    Element.Part <V_IsTrueForAny>(_waitAsyncQueue.Get(), ArrayElementTimeSurpassed(new V_ArrayElement()))
                                    ));

            // Get the affected item.
            var item = DeltinScript.VarCollection.Assign("waitAsync_item", true, false);

            rule.ActionSet.AddAction(item.SetVariable(Element.Part <V_FirstOf>(Element.Part <V_FilteredArray>(
                                                                                   Element.Part <V_MappedArray>(_waitAsyncQueue.Get(), new V_CurrentArrayIndex()),
                                                                                   ArrayElementTimeSurpassed(_waitAsyncQueue.Get()[new V_ArrayElement()])
                                                                                   ))));

            // Activate item lambda.
            DeltinScript.GetComponent <LambdaGroup>().Call(rule.ActionSet.New(Element.Part <V_LastOf>(_waitAsyncQueue.Get()[item.Get()])), new CallHandler());

            // Remove from queue.
            rule.ActionSet.AddAction(_waitAsyncQueue.ModifyVariable(Operation.RemoveFromArrayByIndex, item.Get()));

            // Loop if another item needs to execute on the same tick.
            rule.ActionSet.AddAction(Element.Part <A_LoopIfConditionIsTrue>());

            // Get the rule.
            DeltinScript.WorkshopRules.Add(rule.GetRule());
        }
Ejemplo n.º 14
0
        protected IWorkshopTree RenderModel(ActionSet actionSet, Model model, Element visibleTo, Element location, Element rotation, Element scale, IWorkshopTree reevaluation, bool getEffectIDs)
        {
            IndexReference effects = null;

            if (getEffectIDs)
            {
                effects = actionSet.VarCollection.Assign("_modelEffects", actionSet.IsGlobal, true);
                actionSet.AddAction(effects.SetVariable(new V_EmptyArray()));
            }

            for (int i = 0; i < model.Lines.Length; i++)
            {
                CreateLine(actionSet, model.Lines[i], visibleTo, location, rotation, scale, reevaluation);

                // Get the last created effect and append it to the store array.
                if (effects != null)
                {
                    actionSet.AddAction(effects.ModifyVariable(Operation.AppendToArray, new V_LastCreatedEntity()));
                }

                // Add a wait every 12 effects to prevent high server load.
                if (i % 10 == 0)
                {
                    actionSet.AddAction(A_Wait.MinimumWait);
                }
            }

            return(effects?.GetVariable());
        }
Ejemplo n.º 15
0
        private void SetInitialUnvisited()
        {
            // Create an array counting up to the number of values in the nodeArray array.
            // For example, if nodeArray has 6 variables unvisitedVar will be set to [0, 1, 2, 3, 4, 5].

            // Empty the unvisited array.
            actionSet.AddAction(unvisited.SetVariable(new V_EmptyArray()));

            IndexReference current = actionSet.VarCollection.Assign("unvisitedBuilder", actionSet.IsGlobal, assignExtended);

            actionSet.AddAction(current.SetVariable(0));

            // While current < the count of the node array.
            actionSet.AddAction(Element.Part <A_While>((Element)current.GetVariable() < Element.Part <V_CountOf>(Nodes)));

            // If there can be null nodes, make sure the node is not null.
            if (resolveInfo.PotentiallyNullNodes)
            {
                actionSet.AddAction(Element.Part <A_If>(new V_Compare(Nodes[current.Get()], Operators.NotEqual, new V_Null())));
            }

            actionSet.AddAction(unvisited.ModifyVariable(Operation.AppendToArray, (Element)current.GetVariable()));

            // End the if.
            if (resolveInfo.PotentiallyNullNodes)
            {
                actionSet.AddAction(new A_End());
            }

            actionSet.AddAction(current.ModifyVariable(Operation.Add, 1));

            // End the while.
            actionSet.AddAction(new A_End());
        }
        public SubroutineCatalogItem Initiate()
        {
            // Setup the subroutine element.
            Subroutine subroutine = _deltinScript.SubroutineCollection.NewSubroutine(_context.ElementName);

            // Create the rule.
            _subroutineRule = new TranslateRule(_deltinScript, subroutine, _context.RuleName, _context.VariableGlobalDefault);

            // Setup the return handler.
            _actionSet = _subroutineRule.ActionSet
                         .ContainVariableAssigner()
                         .SetThisTypeLinker(_context.TypeLinker)
                         .New(_context.Controller.Attributes.IsRecursive);

            // Create the function builder.
            var controller = _context.Controller;

            // Create the parameter handlers.
            _parameterHandler = controller.CreateParameterHandler(_actionSet, null);

            // If the subroutine is an object function inside a class, create a variable to store the class object.
            if (controller.Attributes.IsInstance)
            {
                _objectStore = _actionSet.VarCollection.Assign(_context.ObjectStackName, true, !controller.Attributes.IsRecursive);

                // Set the objectStore as an empty array if the subroutine is recursive.
                if (controller.Attributes.IsRecursive)
                {
                    // Initialize as empty array.
                    _actionSet.InitialSet().AddAction(_objectStore.SetVariable(Element.EmptyArray()));

                    // Add to assigner with the last of the objectStore stack being the object instance.
                    _context.ContainingType?.AddObjectVariablesToAssigner(_actionSet.ToWorkshop, Element.LastOf(_objectStore.GetVariable()), _actionSet.IndexAssigner);

                    // Set the actionSet.
                    _actionSet = _actionSet.New(Element.LastOf(_objectStore.Get())).PackThis().New(_objectStore.CreateChild(Element.CountOf(_objectStore.Get()) - 1));
                }
                else
                {
                    // Add to assigner with the objectStore being the object instance.
                    _context.ContainingType?.AddObjectVariablesToAssigner(_actionSet.ToWorkshop, _objectStore.GetVariable(), _actionSet.IndexAssigner);

                    // Set the actionSet.
                    _actionSet = _actionSet.New(_objectStore.Get()).PackThis().New(_objectStore);
                }
            }

            _functionBuilder = new WorkshopFunctionBuilder(_actionSet, controller);
            _functionBuilder.ModifySet(a => a.PackThis()); // TODO: is this required?
            _functionBuilder.SetupReturnHandler();
            _parameterHandler.AddParametersToAssigner(_actionSet.IndexAssigner);

            // Done.
            return(Result = new SubroutineCatalogItem(
                       subroutine: subroutine,
                       parameterHandler: _parameterHandler,
                       objectStack: _objectStore,
                       returnHandler: _functionBuilder.ReturnHandler));
        }
        protected void Backtrack(Element destination, IndexReference finalPath)
        {
            actionSet.AddAction(current.SetVariable(destination));
            actionSet.AddAction(finalPath.SetVariable(new V_EmptyArray()));

            // Get the path.
            actionSet.AddAction(Element.Part <A_While>(new V_Compare(
                                                           current.GetVariable(),
                                                           Operators.GreaterThanOrEqual,
                                                           new V_Number(0)
                                                           )));

            // !WAIT actionSet.AddAction(A_Wait.MinimumWait);

            Element next  = Nodes[(Element)current.GetVariable()];
            Element array = (Element)finalPath.GetVariable();
            Element first;
            Element second;

            if (!reversed)
            {
                first  = next;
                second = array;
            }
            else
            {
                first  = array;
                second = next;
            }

            // For debugging generated path.
            // actionSet.AddAction(Element.Part<A_CreateEffect>(
            //     Element.Part<V_AllPlayers>(),
            //     EnumData.GetEnumValue(Effect.Orb),
            //     EnumData.GetEnumValue(Color.SkyBlue),
            //     next,
            //     new V_Number(0.5),
            //     EnumData.GetEnumValue(EffectRev.VisibleTo)
            // ));

            actionSet.AddAction(ArrayBuilder <Element> .Build(
                                    finalPath.SetVariable(Element.Part <V_Append>(first, second)),
                                    current.SetVariable(Element.Part <V_ValueInArray>(parentArray.GetVariable(), current.GetVariable()) - 1)
                                    ));
            actionSet.AddAction(new A_End());
        }
Ejemplo n.º 18
0
        protected void Backtrack(Element startNode, IndexReference finalPath, IndexReference finalPathAttributes, bool reversePath = false)
        {
            actionSet.AddAction(current.SetVariable(startNode));
            actionSet.AddAction(finalPath.SetVariable(new V_EmptyArray()));

            // Get the path.
            actionSet.AddAction(Element.Part <A_While>(new V_Compare(
                                                           current.GetVariable(),
                                                           Operators.GreaterThanOrEqual,
                                                           new V_Number(0)
                                                           )));

            Element nextNode      = Nodes[(Element)current.GetVariable()];
            Element nextAttribute = ((Element)parentAttributeInfo.GetVariable())[(Element)current.GetVariable()];

            // For debugging generated path.
            // actionSet.AddAction(Element.Part<A_CreateEffect>(
            //     Element.Part<V_AllPlayers>(),
            //     EnumData.GetEnumValue(Effect.Orb),
            //     EnumData.GetEnumValue(Color.SkyBlue),
            //     next,
            //     new V_Number(0.5),
            //     EnumData.GetEnumValue(EffectRev.VisibleTo)
            // ));

            if (!reversePath)
            {
                // Add the current node to the final path.
                actionSet.AddAction(finalPath.ModifyVariable(Operation.AppendToArray, nextNode));
                // Add the current attribute to the final path attributes.
                if (useAttributes)
                {
                    actionSet.AddAction(finalPathAttributes.ModifyVariable(Operation.AppendToArray, nextAttribute));
                }
            }
            else
            {
                // Insert the current node to the final path.
                actionSet.AddAction(finalPath.SetVariable(Element.Part <V_Append>(nextNode, finalPath.GetVariable())));
                // Insert the current attribute to the final path attributes.
                actionSet.AddAction(finalPathAttributes.SetVariable(Element.Part <V_Append>(nextAttribute, finalPathAttributes.GetVariable())));
            }

            actionSet.AddAction(current.SetVariable(Element.Part <V_ValueInArray>(parentArray.GetVariable(), current.GetVariable()) - 1));
            actionSet.AddAction(new A_End());
        }
        override protected void Assign()
        {
            var lastNode = ClosestNodeToPosition(Nodes, destination);

            finalNode = actionSet.VarCollection.Assign("Dijkstra: Last", actionSet.IsGlobal, true);
            finalPath = actionSet.VarCollection.Assign("Dijkstra: Final Path", actionSet.IsGlobal, false);
            actionSet.AddAction(finalNode.SetVariable(lastNode));
            actionSet.AddAction(finalPath.SetVariable(new V_EmptyArray()));
        }
Ejemplo n.º 20
0
 protected override void Assign()
 {
     finalPath = actionSet.VarCollection.Assign("Dijkstra: Final Path", actionSet.IsGlobal, false);
     actionSet.AddAction(finalPath.SetVariable(new V_EmptyArray()));
     if (useAttributes)
     {
         finalPathAttributes = actionSet.VarCollection.Assign("Dijkstra: Final Path Attributes", actionSet.IsGlobal, false);
         actionSet.AddAction(finalPathAttributes.SetVariable(new V_EmptyArray()));
     }
 }
Ejemplo n.º 21
0
        protected override void Assign()
        {
            potentialDestinations = actionSet.VarCollection.Assign("Dijkstra: Potential Destinations", actionSet.IsGlobal, false);
            actionSet.AddAction(potentialDestinations.SetVariable(new V_EmptyArray()));
            chosenDestination = actionSet.VarCollection.Assign("Dijkstra: Chosen Destination", actionSet.IsGlobal, assignExtended);

            ForeachBuilder getClosestNodes = new ForeachBuilder(actionSet, destinations);

            actionSet.AddAction(potentialDestinations.ModifyVariable(Operation.AppendToArray, GetClosestNode(actionSet, Nodes, getClosestNodes.IndexValue)));
            getClosestNodes.Finish();
        }
Ejemplo n.º 22
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            Element player = (Element)parameterValues[0];

            IndexReference originalHero = actionSet.VarCollection.Assign("isAI_originalHero", actionSet.IsGlobal, true);
            IndexReference isAI         = actionSet.VarCollection.Assign("isAI_originalHero", actionSet.IsGlobal, true);

            actionSet.AddAction(ArrayBuilder <Element> .Build
                                (
                                    originalHero.SetVariable(Element.Part <V_HeroOf>(player)),
                                    Element.Part <A_SkipIf>(Element.Part <V_Compare>(originalHero.GetVariable(), EnumData.GetEnumValue(Operators.NotEqual), new V_Null()), new V_Number(2)),
                                    isAI.SetVariable(new V_False()),
                                    Element.Part <A_Skip>(new V_Number(4)),
                                    Element.Part <A_ForcePlayerHero>(player, EnumData.GetEnumValue(Hero.Ashe)),
                                    isAI.SetVariable(Element.Part <V_Compare>(Element.Part <V_HeroOf>(player), EnumData.GetEnumValue(Operators.NotEqual), EnumData.GetEnumValue(Hero.Ashe))),
                                    Element.Part <A_ForcePlayerHero>(player, originalHero.GetVariable()),
                                    Element.Part <A_StopForcingHero>(player)
                                ));

            return(isAI.GetVariable());
        }
        protected override void Init()
        {
            // Assign an array that will be used to store the closest node to each player.
            _closestNodesToPlayers = ActionSet.VarCollection.Assign("Dijkstra: Closest nodes", ActionSet.IsGlobal, false);
            ActionSet.AddAction(_closestNodesToPlayers.SetVariable(EmptyArray()));

            // Loop through each player and get the closest node.
            ForeachBuilder getClosestNodes = new ForeachBuilder(ActionSet, _players);

            ActionSet.AddAction(_closestNodesToPlayers.ModifyVariable(Operation.AppendToArray, NodeFromPosition(getClosestNodes.IndexValue)));
            getClosestNodes.Finish();
        }
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            IndexReference destinationStore = actionSet.VarCollection.Assign("_pathfindDestinationStore", actionSet.IsGlobal, true);

            actionSet.AddAction(destinationStore.SetVariable((Element)parameterValues[1]));

            DijkstraNormal algorithm = new DijkstraNormal(
                actionSet, (Element)actionSet.CurrentObject, (Element)parameterValues[0], (Element)destinationStore.GetVariable()
                );

            algorithm.Get();

            return(Element.Part <V_Append>(algorithm.finalPath.GetVariable(), destinationStore.GetVariable()));
        }
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            IndexReference destinationStore = actionSet.VarCollection.Assign("_pathfindDestinationStore", actionSet.IsGlobal, true);

            actionSet.AddAction(destinationStore.SetVariable((Element)parameterValues[1]));

            DijkstraMultiSource algorithm = new DijkstraMultiSource(
                actionSet, actionSet.Translate.DeltinScript.SetupPathfinder(), (Element)actionSet.CurrentObject, (Element)parameterValues[0], (Element)destinationStore.GetVariable()
                );

            algorithm.Get();

            return(null);
        }
Ejemplo n.º 26
0
        override protected void Assign()
        {
            var lastNode = GetClosestNode(actionSet, Nodes, destination);

            finalNode = actionSet.VarCollection.Assign("Dijkstra: Last", actionSet.IsGlobal, assignExtended);
            finalPath = actionSet.VarCollection.Assign("Dijkstra: Final Path", actionSet.IsGlobal, false);
            actionSet.AddAction(finalNode.SetVariable(lastNode));
            actionSet.AddAction(finalPath.SetVariable(new V_EmptyArray()));
            if (useAttributes)
            {
                finalPathAttributes = actionSet.VarCollection.Assign("Dijkstra: Final Path Attributes", actionSet.IsGlobal, false);
                actionSet.AddAction(finalPathAttributes.SetVariable(new V_EmptyArray()));
            }
        }
        /// <summary>Looks at a player's future nodes.</summary>
        public Element IsTravelingToAttribute(ActionSet actionSet, Element targetPlayer, Element attribute)
        {
            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(
                                                                                look.GetVariable(),
                                                                                Operators.GreaterThanOrEqual,
                                                                                new V_Number(0)
                                                                                ), !result.Get())));

            actionSet.AddAction(result.SetVariable(new V_Compare(attribute, Operators.Equal, AttributeArray.Get(targetPlayer)[look.Get()])));

            actionSet.AddAction(look.SetVariable(ParentArray.Get(targetPlayer)[look.Get()] - 1));
            actionSet.AddAction(new A_End());

            return(result.Get());
        }
        protected void Backtrack(Element destination, IndexReference finalPath)
        {
            actionSet.AddAction(current.SetVariable(destination));
            actionSet.AddAction(finalPath.SetVariable(new V_EmptyArray()));

            // Get the path.
            WhileBuilder backtrack = new WhileBuilder(actionSet, new V_Compare(
                                                          current.GetVariable(),
                                                          Operators.NotEqual,
                                                          new V_Number(-1)
                                                          ));

            backtrack.Setup();

            Element next  = Nodes[(Element)current.GetVariable()];
            Element array = (Element)finalPath.GetVariable();
            Element first;
            Element second;

            if (!reversed)
            {
                first  = next;
                second = array;
            }
            else
            {
                first  = array;
                second = next;
            }

            actionSet.AddAction(ArrayBuilder <Element> .Build(
                                    finalPath.SetVariable(Element.Part <V_Append>(first, second)),
                                    current.SetVariable(Element.Part <V_ValueInArray>(parentArray.GetVariable(), current.GetVariable()) - 1)
                                    ));
            backtrack.Finish();
        }
        public void Init()
        {
            // Create the array used for continuing after a recursive call.
            _continueArray = varCollection.Assign("_" + name + "_recursiveContinue", isGlobal, false);
            _nextContinue  = varCollection.Assign("_" + name + "_nextContinue", isGlobal, true);
            actionSet.InitialSet().AddAction(_continueArray.SetVariable(Element.EmptyArray()));

            if (_builder.Controller.Attributes.RecursiveRequiresObjectStack)
            {
                _objectStore = varCollection.Assign("_" + name + "_objectStack", isGlobal, false);
                actionSet.AddAction(_objectStore.SetVariable(Element.CreateArray(actionSet.CurrentObject)));

                _builder.ModifySet(actionSet => actionSet.New(Element.LastOf(_objectStore.GetVariable())).PackThis());
            }
            _builder.ModifySet(actionSet => actionSet.New(true));
        }
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            // Store the pathfind destination.
            IndexReference destinationStore = actionSet.VarCollection.Assign("_pathfindDestinationStore", actionSet.IsGlobal, true);

            actionSet.AddAction(destinationStore.SetVariable((Element)parameterValues[1]));

            DijkstraNormal algorithm = new DijkstraNormal(
                actionSet, (Element)actionSet.CurrentObject, Element.Part <V_PositionOf>(parameterValues[0]), (Element)destinationStore.GetVariable()
                );

            algorithm.Get();
            DijkstraBase.Pathfind(
                actionSet, actionSet.Translate.DeltinScript.SetupPathfinder(), (Element)algorithm.finalPath.GetVariable(), (Element)parameterValues[0], (Element)destinationStore.GetVariable()
                );

            return(null);
        }