public override void AddObjectVariablesToAssigner(IWorkshopTree reference, VarIndexAssigner assigner)
 {
     assigner.Add(Node_A, DijkstraBase.Node1((Element)reference));
     assigner.Add(Node_B, DijkstraBase.Node2((Element)reference));
     assigner.Add(Attribute_AB, DijkstraBase.Node1Attribute((Element)reference));
     assigner.Add(Attribute_BA, DijkstraBase.Node2Attribute((Element)reference));
 }
Exemple #2
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            DijkstraNormal algorithm = new DijkstraNormal(
                actionSet, (Element)actionSet.CurrentObject.GetVariable(), Element.Part <V_PositionOf>(parameterValues[0]), (Element)parameterValues[1]
                );

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

            return(null);
        }
 public Element SegmentsFromNodes(IWorkshopTree pathmapObject, Element node1, Element node2) => Element.Part <V_FilteredArray>(
     Segments.Get()[(Element)pathmapObject],
     Element.Part <V_And>(
         Element.Part <V_ArrayContains>(
             DijkstraBase.BothNodes(new V_ArrayElement()),
             node1
             ),
         Element.Part <V_ArrayContains>(
             DijkstraBase.BothNodes(new V_ArrayElement()),
             node2
             )
         )
     );
        /// <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));
            }
        }
        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);
        }
        private void SetHooks(DijkstraBase algorithm, IWorkshopTree onLoop, IWorkshopTree onConnectLoop)
        {
            // OnLoop
            if (onLoop is LambdaAction onLoopLambda)
            {
                algorithm.OnLoop = actionSet => onLoopLambda.Invoke(actionSet);
            }

            // OnConnectLoop
            if (onConnectLoop is LambdaAction onConnectLoopLambda)
            {
                algorithm.OnConnectLoop = actionSet => onConnectLoopLambda.Invoke(actionSet);
            }

            if (ApplicableNodeDeterminer.HookValue != null)
            {
                algorithm.GetClosestNode = (actionSet, nodes, position) => (Element)((LambdaAction)ApplicableNodeDeterminer.HookValue).Invoke(actionSet, nodes, position);
            }
        }
        override protected MethodResult Get(PathfinderInfo info)
        {
            if (((VarRef)Parameters[1]).Var is PathMapVar == false)
            {
                throw SyntaxErrorException.InvalidVarRefType(((VarRef)Parameters[1]).Var.Name, VarType.PathMap, ParameterLocations[1]);
            }

            Element    player  = (Element)Parameters[0];
            PathMapVar pathmap = (PathMapVar)((VarRef)Parameters[1]).Var;

            IndexedVar destination = IndexedVar.AssignInternalVarExt(TranslateContext.VarCollection, Scope, "Destination", TranslateContext.IsGlobal);

            TranslateContext.Actions.AddRange(destination.SetVariable((Element)Parameters[2]));

            DijkstraNormal algorithm = new DijkstraNormal(TranslateContext, pathmap, Element.Part <V_PositionOf>(player), destination.GetVariable());

            algorithm.Get();
            DijkstraBase.Pathfind(TranslateContext, info, algorithm.finalPath.GetVariable(), player, destination.GetVariable());
            return(new MethodResult(null, null));
        }