/// <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);
        }
Пример #2
0
        public void RemoveAttribute(Attribute attr)
        {
            if (attr == null)
            {
                throw new ArgumentNullException(nameof(attr));
            }
            var attrs = AttributeArray.ToList();

            if (attrs.Remove(attr))
            {
                AttributeArray = attrs.ToArray();
            }
        }
Пример #3
0
        public void AddAttribute(Attribute attr)
        {
            if (attr == null)
            {
                throw new ArgumentNullException(nameof(attr));
            }
            var attrs = AttributeArray.ToList();

            if (!attrs.Contains(attr))
            {
                attrs.Add(attr);
                AttributeArray = attrs.ToArray();
            }
        }
        /// <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());
        }
 /// <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)
     );