Example #1
0
        public void ExplosionPredictionWorks()
        {
            var entity      = World.Global.SpawnEntity(Dummy.Factory, new IntVector2(1, 1));
            var info        = new PredictionTargetInfo(Layers.Any, Faction.Any);
            var predictions = Explosion.DefaultExplodeAction(1).Predict(entity, info).ToArray();

            Assert.AreEqual(9, predictions.Length, "Would explode 9 cells");
        }
 /// <summary>
 /// This function returns positions and directions that could target the entity
 /// from the given layer and of the given faction if the GetTargets()
 /// function were to be evaluated with the given position and direction.
 /// If the target provider may never target the given layer / faction,
 /// this returns an empty enumerable.
 /// </summary>
 public IEnumerable <PositionAndDirection> PredictPositionsAndDirections(
     IntVector2 position, IntVector2 direction, PredictionTargetInfo info)
 {
     if (WhetherMayAffect(info.layer, info.faction))
     {
         return(_pattern.GetPositionsAndDirections(position, direction));
     }
     return(Enumerable.Empty <PositionAndDirection>());
 }
Example #3
0
        /// <summary>
        /// Returns the positions that would be attacked if the behavior's activate were to be called.
        /// TODO: use the info on layers and the faction to return better estimations
        /// </summary>
        public IEnumerable <IntVector2> Predict(Entity actor, IntVector2 direction, PredictionTargetInfo info)
        {
            // If the entity would not be targeted, skip
            if (info.faction.HasNeitherFlag(targetedFaction) || info.layer.HasNeitherFlag(targetedLayer))
            {
                yield break;
            }

            // TODO: maybe generalize this to use the SetTargets chain.
            var provider = GetDefaultAttackTargetProvider(actor);

            if (provider is null)
            {
                yield break;
            }

            foreach (var ctx in provider._pattern.MakeContexts(actor.GetTransform().position, direction))
            {
                // This has more info, can use.
                // TODO: The info contains
                yield return(ctx.position);
            }
        }
Example #4
0
        public void ProviderPredictionWorks()
        {
            var pattern  = new StraightPattern(Layers.WALL);
            var provider = new UnbufferedTargetProvider(pattern, Layers.REAL, Faction.Any);

            // Generating predictions relative to this point
            var info = new PredictionTargetInfo(Layers.REAL, Faction.Player);

            var positions = provider.PredictPositions(IntVector2.Zero, IntVector2.Right, info);

            Assert.AreEqual(2, positions.Count());

            var wall = World.Global.SpawnEntity(Wall.Factory, new IntVector2(1, 0));

            positions = provider.PredictPositions(IntVector2.Zero, IntVector2.Right, info);

            Assert.AreEqual(0, positions.Count());

            wall.GetTransform().ResetPositionInGrid(new IntVector2(2, 0));
            positions = provider.PredictPositions(IntVector2.Zero, IntVector2.Right, info);

            Assert.AreEqual(1, positions.Count());
        }
 /// <summary>
 /// This function returns positions that could target the entity
 /// from the given layer and of the given faction if the GetTargets()
 /// function were to be evaluated with the given position and direction.
 /// If the target provider may never target the given layer / faction,
 /// this returns an empty enumerable.
 /// </summary>
 public IEnumerable <IntVector2> PredictPositions(
     IntVector2 position, IntVector2 direction, PredictionTargetInfo info)
 {
     return(PredictPositionsAndDirections(position, direction, info).Select(pd => pd.position));
 }
 public IEnumerable <PositionAndDirection> PredictPositionsAndDirectionsBy(
     Entity actor, IntVector2 direction, PredictionTargetInfo info)
 {
     return(PredictPositionsAndDirections(actor.GetTransform().position, direction, info));
 }
Example #7
0
 public IEnumerable <IntVector2> Predict(Entity actor, IntVector2 direction, PredictionTargetInfo info)
 {
     return(_provider.PredictPositionsBy(actor, direction, info));
 }