/// <summary> /// Calculates all possibilities to move next to the Entity provided by <paramref name="p_moveToEntityNode"/>. /// </summary> private static IEnumerable <ADecisionNode> createMoveToNavigationNodesLink(DecisionTree p_aiDecisionTree, MoveToEntityNode p_moveToEntityNode) { var l_reachableNavigationNodes = NavigationGraphAlgorithm.getReachableNeighborNavigationNodes( NavigationGraphContainer.UniqueNavigationGraph, p_moveToEntityNode.TargetEntity.CurrentNavigationNode, NavigationGraphFlag.CURRENT).GetEnumerator(); while (l_reachableNavigationNodes.MoveNext()) { MoveToNavigationNodeNode l_moveToNavigationNodeNode = MoveToNavigationNodeNode.alloc(p_moveToEntityNode.SourceEntity.CurrentNavigationNode, l_reachableNavigationNodes.Current); DecisionTree.linkDecisionNodes(p_aiDecisionTree, p_moveToEntityNode, l_moveToNavigationNodeNode); yield return(l_moveToNavigationNodeNode); } /* If the source entity is already a neighbor of the target entity, we still create a node to move to same position to simulate the fact of staying at the same position. */ if (NavigationGraphAlgorithm.areNavigationNodesNeighbors( NavigationGraphContainer.UniqueNavigationGraph, p_moveToEntityNode.SourceEntity.CurrentNavigationNode, p_moveToEntityNode.TargetEntity.CurrentNavigationNode, NavigationGraphFlag.SNAPSHOT)) { MoveToNavigationNodeNode l_moveToNavigationNodeNode = MoveToNavigationNodeNode.alloc(p_moveToEntityNode.SourceEntity.CurrentNavigationNode, p_moveToEntityNode.SourceEntity.CurrentNavigationNode); DecisionTree.linkDecisionNodes(p_aiDecisionTree, p_moveToEntityNode, l_moveToNavigationNodeNode); yield return(l_moveToNavigationNodeNode); } }
public void TriggerComponentTest_navigationNodeMove() { // Initializing trigger Entity Entity l_testTriggerEntity = Entity.alloc(); l_testTriggerEntity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); EntityComponent.add_component(l_testTriggerEntity, NavigationEngineTestTriggerComponent.alloc()); EntityComponent.add_component(l_testTriggerEntity, Locomotion.alloc(new LocomotionData() { Speed = float.MaxValue * 0.1f })); // We warp the l_testTriggeredEntity to a random NavigationNode EventQueue.enqueueEvent( TestEventQueue, NavigationNodeWarpEntityEvent.alloc( l_testTriggerEntity, NavigationGraphAlgorithm.pickRandomNode(NavigationGraphContainer.UniqueNavigationGraph) ) ); EventQueue.iterate(TestEventQueue); // We create the Entity that will be involved in the trigger Entity l_entity = Entity.alloc(); l_entity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); EntityComponent.add_component(l_entity, Locomotion.alloc(new LocomotionData() { Speed = float.MaxValue * 0.1f })); ActionPointData l_actionPointdata = new ActionPointData() { InitialActionPoints = 999f, CurrentActionPoints = 999f }; EntityComponent.add_component(l_entity, ActionPoint.alloc(ref l_actionPointdata)); var l_entityNavigationNodeEnumerator = NavigationGraphAlgorithm.getReachableNeighborNavigationNodes(NavigationGraphContainer.UniqueNavigationGraph, l_testTriggerEntity.CurrentNavigationNode, NavigationGraphFlag.CURRENT).GetEnumerator(); l_entityNavigationNodeEnumerator.MoveNext(); EventQueue.enqueueEvent( TestEventQueue, NavigationNodeWarpEntityEvent.alloc( l_entity, l_entityNavigationNodeEnumerator.Current ) ); NavigationNodeMoveEvent l_navigationNodeMoveEvent = NavigationNodeMoveEvent.alloc(l_entity, l_testTriggerEntity.CurrentNavigationNode); EventQueue.enqueueEvent( TestEventQueue, l_navigationNodeMoveEvent ); while (!l_navigationNodeMoveEvent.IsCompleted()) { LocomotionSystemV2Container.Tick(1.0f); EventQueue.iterate(TestEventQueue); } NavigationEngineTestTriggerComponent l_triggerComponent = EntityComponent.get_component <NavigationEngineTestTriggerComponent>(l_testTriggerEntity); Assert.IsTrue(l_triggerComponent.IsTriggered); Assert.IsTrue(l_triggerComponent.TriggeredEntity == l_entity); }