Ejemplo n.º 1
0
        protected override Task AliveAsync()
        {
            // await base.AliveAsync();

            foreach (var sensor in Sensors)
            {
                sensor.Sense();
            }
            var contexts = ContextBehaviors.Select(b => b.Behave(Steps)).ToList();

            (var finalRing, var angle, var boost) = ContextRingBlending.Blend(contexts, true);
            SteerAngle(angle);
            var willShoot = CanShoot;

            if (CanBoost && boost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                if (ShootUntil < GameTime)
                {
                    Boost();
                }
                willShoot = false;
            }
            if (CanShoot && willShoot)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    var  shootAngle = MathF.Atan2(target.Position.Y - this.Position.Y, target.Position.X - this.Position.X);
                    bool dangerous  = false;
                    if (!AttackFleets && this.SensorFleets.MyFleet != null)
                    {
                        var flets = FleetTargeting.PotentialTargetFleets();
                        foreach (var flet in flets)
                        {
                            if (RoboMath.MightHit(this.HookComputer, this.SensorFleets.MyFleet, flet, shootAngle))
                            {
                                dangerous = true;
                            }
                        }
                    }
                    if (!Safe || !dangerous)
                    {
                        ShootAt(target.Position);
                    }
                }
            }



            if (ReloadConfigAfter > 0 && ReloadConfigAfter < GameTime)
            {
                LoadConfig();
                ReloadConfigAfter = 0;
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 2
0
        public TreeState ProjectClone(int time, float angle, bool stay)
        {
            Fleet newF     = this.Fleet.Clone();
            var   momentum = newF.Momentum;
            var   position = RoboMath.ShipThrustProjection(TRobot.HookComputer,
                                                           newF.Center,
                                                           ref momentum,
                                                           newF.Ships.Count,
                                                           angle,
                                                           time
                                                           );

            if (!stay)
            {
                newF.SetMomentumAndPos(position, momentum);
            }

            TreeState ns = new TreeState(OffsetMS + time, newF, TRobot);

            ns.LocalOffsetMS = time;
            ns.Angle         = angle;
            ns.Stay          = stay;
            ns.OldFleet      = this.Fleet.Clone();
            this.Children.Add(ns);
            return(ns);
        }
Ejemplo n.º 3
0
 private void ShootAtFleet(Fleet f)
 {
     ShootAt(
         RoboMath.FiringIntercept(
             HookComputer,
             this.Position,
             f.Center,
             f.Momentum,
             this.SensorFleets.MyFleet?.Ships.Count ?? 0
             )
         );
 }
Ejemplo n.º 4
0
        protected async override Task AliveAsync()
        {
            await base.AliveAsync();

            // when shooting becomes available
            // lets see if we should delay
            if (!LastCanShoot && CanShoot)
            {
                DeferShootUntil = GameTime + FiringDelayMS;
            }
            LastCanShoot = CanShoot;

            if (CanShoot && DeferShootUntil < GameTime)
            {
                var target = (AttackFleets ? FleetTargeting.ChooseTarget() : null)
                             ?? (AttackAbandoned ? AbandonedTargeting.ChooseTarget() : null)
                             ?? (AttackFish ? FishTargeting.ChooseTarget() : null);

                if (target != null)
                {
                    var  shootAngle = MathF.Atan2(target.Position.Y - this.Position.Y, target.Position.X - this.Position.X);
                    bool dangerous  = false;
                    if (!AttackFleets && this.SensorFleets.MyFleet != null)
                    {
                        var flets = FleetTargeting.PotentialTargetFleets();
                        foreach (var flet in flets)
                        {
                            if (RoboMath.MightHit(this.HookComputer, this.SensorFleets.MyFleet, flet, shootAngle))
                            {
                                dangerous = true;
                            }
                        }
                    }
                    if (!Safe || !dangerous)
                    {
                        ShootAt(target.Position);
                    }
                }
            }

            if (CanBoost && (this.SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                Boost();
            }
        }
Ejemplo n.º 5
0
        public bool IsSafeShot(float angle)
        {
            var safeSet = Safe
                ? SensorFleets.Others
                : SensorFleets.Others.Where(f => SensorAllies.IsAlly(f));

            if (this.SensorFleets.MyFleet != null)
            {
                if (safeSet
                    .Any(f => RoboMath.MightHit(
                             this.HookComputer,
                             this.SensorFleets.MyFleet,
                             f,
                             angle)))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        protected async override Task AliveAsync()
        {
            if (CanShoot)
            {
                var closest = SensorFleets.Others
                              .Select(f => new { Fleet = f, Distance = Vector2.Distance(this.Position, f.Center) })
                              .Where(p => MathF.Abs(p.Fleet.Center.X - this.Position.X) <= ViewportCrop.X &&
                                     MathF.Abs(p.Fleet.Center.Y - this.Position.Y) <= ViewportCrop.Y)
                              .Where(p => !DontFireAtSameName || p.Fleet.Name != this.Name)
                              .Where(p => p.Fleet.Name.Contains(this.Target) || this.Target == "")
                              .Where(p => !HookComputer.Hook.TeamMode || p.Fleet.Color != this.Color)
                              .OrderBy(p => p.Distance)
                              .FirstOrDefault()
                              ?.Fleet;

                if (closest != null)
                {
                    ShootAtFleet(closest);
                }
            }

            if (CanBoost && (SensorFleets.MyFleet?.Ships.Count ?? 0) > BoostThreshold)
            {
                Boost();
            }

            /*CustomData = JsonConvert.SerializeObject(new
             * {
             *  spots = Behaviors.OfType<Dodge>().Where(d => d.ConsideredPoints != null).SelectMany(d => d.ConsideredPoints)
             * });*/


            CustomData = JsonConvert.SerializeObject(new
            {
                spots = SensorFleets.Others?.Select(f => RoboMath.FiringIntercept(HookComputer, this.Position, f.Center, f.Momentum, this.SensorFleets.MyFleet?.Ships.Count ?? 0))
            });

            await base.AliveAsync();
        }