Пример #1
0
        private static void PushEventsFromAIDecision(Entity p_entity, EventQueue p_eventQueue, ref AIDecisionTreeChoice p_aiDecision)
        {
            for (int i = 0; i < p_aiDecision.DecisionNodesChoiceOrdered.Length; i++)
            {
                ADecisionNode l_decisionNode = p_aiDecision.DecisionNodesChoiceOrdered[i];

                switch (l_decisionNode)
                {
                // Push to the event queue the will of moving along a path
                case MoveToNavigationNodeNode l_moveToNavigationNode:
                {
                    EventBuilder.moveToNavigationNode(p_entity, p_eventQueue, l_moveToNavigationNode.NavigationPath);
                }
                break;

                case AttackNode l_attackNode:
                {
                    for (int j = 0; j < l_attackNode.NumberOfAttacks; j++)
                    {
                        EventBuilder.attackEvent(p_entity, p_eventQueue, l_attackNode.SourceEntity, l_attackNode.TargetEntity, l_attackNode.Attack);
                    }
                }
                break;
                }
            }
        }
Пример #2
0
            public static TraversalStack build(ADecisionNode p_decisionNodeHandler)
            {
                TraversalStack l_instance = new TraversalStack();

                l_instance.DecisionNode         = p_decisionNodeHandler;
                l_instance.LinkIterationCounter = 0;
                return(l_instance);
            }
Пример #3
0
        /// <summary>
        /// Traversal of <see cref="DecisionTree"/> is done by recusrively calling the <see cref="ADecisionNode.TreeTraversal(ADecisionNode)"/>.
        /// </summary>
        public static RefList <AIDecisionTreeChoice> traverseDecisionTree(DecisionTree p_decisionTree)
        {
            RefList <AIDecisionTreeChoice> l_choices = new RefList <AIDecisionTreeChoice>();

            RefList <TraversalStack> l_traversalStacks = new RefList <TraversalStack>();

            l_traversalStacks.Add(TraversalStack.build(p_decisionTree.RootNode));

            while (l_traversalStacks.Count > 0)
            {
                ref TraversalStack l_currentTraversalStack = ref l_traversalStacks.ValueRef(l_traversalStacks.Count - 1);
                //If there if the current node has links
                if (l_currentTraversalStack.DecisionNode.LinkedNodes != null)
                {
                    if (l_currentTraversalStack.LinkIterationCounter < l_currentTraversalStack.DecisionNode.LinkedNodes.Count)
                    {
                        //We traverse the link and go one level deeper
                        ADecisionNode l_nextNode = l_currentTraversalStack.DecisionNode.LinkedNodes[l_currentTraversalStack.LinkIterationCounter];

                        l_currentTraversalStack.LinkIterationCounter += 1;
                        TraversalStack l_oneLevelDepperStack = TraversalStack.build(l_nextNode);
                        l_traversalStacks.AddRef(ref l_oneLevelDepperStack);

                        l_nextNode.TreeTraversal(l_currentTraversalStack.DecisionNode);
                    }
                    else
                    {
                        #region Updating stack

                        l_traversalStacks.RemoveAt(l_traversalStacks.Count - 1);

                        #endregion
                    }
                }
                else // No links have been found, this means that the current node is a leaf node.
                {
                    #region Creating the choice as the current node is a leaf

                    ADecisionNode[] l_choiceNodes = new ADecisionNode[l_traversalStacks.Count];
                    for (int i = 0; i < l_traversalStacks.Count; i++)
                    {
                        l_choiceNodes[i] = l_traversalStacks.ValueRef(i).DecisionNode;
                    }

                    AIDecisionTreeChoice l_choice = AIDecisionTreeChoice.build(l_choiceNodes);
                    l_choices.AddRef(ref l_choice);

                    #endregion

                    l_traversalStacks.RemoveAt(l_traversalStacks.Count - 1);
                }
            }
Пример #4
0
        /// <summary>
        /// Build a list of <see cref="ActionPoint"/> consmption predictions.
        /// <see cref="ActionPoint"/> consmption predictions are represented by etries in the return list.
        /// See <see cref="IAtionPointPredictable.AddActionPointPrediction(List{float})"/> for more details.
        /// </summary>
        public static List <float> predictActionPointConsumptions(ref AIDecisionTreeChoice p_choice)
        {
            List <float> l_return = new List <float>();

            for (int i = 0; i < p_choice.DecisionNodesChoiceOrdered.Length; i++)
            {
                ADecisionNode l_decisionNode = p_choice.DecisionNodesChoiceOrdered[i];
                if (l_decisionNode is IAtionPointPredictable)
                {
                    ((IAtionPointPredictable)l_decisionNode).AddActionPointPrediction(l_return);
                }
            }
            return(l_return);
        }
Пример #5
0
 public override void TreeTraversal(ADecisionNode p_sourceNode)
 {
     using (NavigationGraphAlgorithm.CalculatePathRequest l_calculationRequest = NavigationGraphAlgorithm.CalculatePathRequest.CalculatePathRequestPool.popOrCreate())
     {
         NavigationGraphAlgorithm.CalculatePathRequest.prepareForCalculation(
             l_calculationRequest,
             NavigationGraphContainer.UniqueNavigationGraph,
             SourceNavigationNode,
             TargetNavigationNode,
             PathCalculationParameters.build(2.0f));
         NavigationGraphAlgorithm.CalculatePath(l_calculationRequest);
         ref NavigationPath l_calculatedNavigationPath = ref l_calculationRequest.ResultPath;
         NavigationPath = new List <NavigationNode>(l_calculatedNavigationPath.NavigationNodes);
         PathCost       = l_calculatedNavigationPath.PathCost;
     }
Пример #6
0
        public override void TreeTraversal(ADecisionNode p_sourceNode)
        {
            //TODO -> Store executed attacks in a vector, then the consumer read the vector and transforms them in EntityActions.
            ActionPoint     l_sourceEntityActionPoint = EntityComponent.get_component <ActionPoint>(SourceEntity);
            ActionPointData l_virtualActionPointData  = new ActionPointData()
            {
                InitialActionPoints = l_sourceEntityActionPoint.ActionPointData.InitialActionPoints,
                CurrentActionPoints = l_sourceEntityActionPoint.ActionPointData.InitialActionPoints
            };

            while (l_virtualActionPointData.CurrentActionPoints >= Attack.AttackData.APCost)
            {
                ActionPointData.add(ref l_virtualActionPointData, -1 * Attack.AttackData.APCost);
                DamageDone      += Attack.AttackData.Damage;
                NumberOfAttacks += 1;
            }
        }
Пример #7
0
        private static IEnumerable <ADecisionNode> createMoveToEntityTree(DecisionTree p_aiDecisionTree, ADecisionNode p_rootNode, Entity p_sourceEntity, Entity p_targetEntity)
        {
            MoveToEntityNode l_moveToEntityNode = MoveToEntityNode.alloc(p_sourceEntity, p_targetEntity);

            DecisionTree.linkDecisionNodes(p_aiDecisionTree, p_rootNode, l_moveToEntityNode);
            return(createMoveToNavigationNodesLink(p_aiDecisionTree, l_moveToEntityNode));
        }
Пример #8
0
 public override void TreeTraversal(ADecisionNode p_sourceNode)
 {
     base.TreeTraversal(p_sourceNode);
     RecoveredHealth += TargetHealTrigger.HealthRecoveryData.RecoveredHealth;
 }