コード例 #1
0
        public override bool AddMorePilots()
        {
            var bs = _game.AllBases.Where(_ => _.Team == AI.Team && _.Active && _.CanLaunchShips()).ToList();

            if (bs.Count == 0)
            {
                return(false);
            }
            var b = bs[StrategyGame.Random.Next(bs.Count)];

            // launch a scout if possible
            var ship = _game.Ships.CreateCombatShip(Keys.S, AI.Team, AI.TeamColour, b.SectorId);

            if (ship == null)
            {
                return(false);
            }
            if (!_game.LaunchShip(ship))
            {
                return(false);
            }

            ship.CenterX = b.CenterX;
            ship.CenterY = b.CenterY;

            var pos = b.GetNextBuildPosition();

            ship.ShipEvent += _shipHandler;
            ship.OrderShip(new MoveOrder(_game, b.SectorId, pos, Point.Empty));

            IncludedShips.Add(ship);
            return(true);
        }
コード例 #2
0
        public override bool RequireMorePilots()
        {
            _shipsToProtect = _game.AllUnits.Where(_ => _.Alliance == AI.Alliance && !_.Docked && _.Active && (_.Type == EShipType.Constructor || _.Type == EShipType.Miner || _.CanAttackBases())).ToList();

            var currentPilots = IncludedShips.Sum(_ => _.NumPilots);

            return(currentPilots < _shipsToProtect.Count * 3);
        }
コード例 #3
0
        public override bool AddMorePilots()
        {
            if (_launchBase == null || _targetBase == null || !_launchBase.Active || !_targetBase.Active || _targetBase.Alliance == AI.Alliance || _launchBase.Team != AI.Team)
            {
                CheckForNewTarget();
            }
            if (_launchBase == null || _targetBase == null)
            {
                return(false);
            }

            // Send any cap ships for support
            var capships = _game.AllUnits.Where(_ => _.Active && _.Team == AI.Team && Ship.IsCapitalShip(_.Type) && _.CurrentOrder == null).ToList();

            IncludedShips.AddRange(capships);

            Ship ship;
            var  t = AI.Team - 1;

            ship = _game.Ships.CreateBomberShip(AI.Team, AI.TeamColour, _launchBase.SectorId);
            if (ship == null)
            {
                if (StrategyGame.RandomChance(0.3f))
                {
                    ship = _game.Ships.CreateCombatShip(AI.Team, AI.TeamColour, _launchBase.SectorId);
                }
                else
                {
                    ship = _game.Ships.CreateCombatShip(Keys.S, AI.Team, AI.TeamColour, _launchBase.SectorId);
                }
            }
            if (ship == null)
            {
                return(false);
            }
            if (!_game.LaunchShip(ship))
            {
                return(false);
            }

            ship.CenterX = _launchBase.CenterX;
            ship.CenterY = _launchBase.CenterY;

            var pos = _launchBase.GetNextBuildPosition();

            ship.ShipEvent += _shipHandler;
            ship.OrderShip(new MoveOrder(_game, _launchBase.SectorId, pos, Point.Empty));

            IncludedShips.Add(ship);
            return(true);
        }
コード例 #4
0
        public virtual void ReducePilots(float chance)
        {
            var dockedShips = new List <Ship>();

            foreach (var s in IncludedShips)
            {
                if (StrategyGame.RandomChance(chance))
                {
                    s.OrderShip(new DockOrder(_game, s));
                    LogOrder();
                    dockedShips.Add(s);
                }
            }
            if (dockedShips.Count > 0)
            {
                IncludedShips.RemoveAll(dockedShips.Contains);
            }
        }
コード例 #5
0
        public override bool AddMorePilots()
        {
            if (_shipsToProtect.Count == 0)
            {
                return(false);
            }

            var s          = _shipsToProtect[StrategyGame.Random.Next(_shipsToProtect.Count)];
            var launchBase = _game.ClosestSectorWithBase(AI.Team, s.SectorId);

            if (launchBase == null)
            {
                return(false);
            }

            Ship ship = null;

            // launch scouts and our best pilotable combat ships
            if (StrategyGame.RandomChance(0.5f))
            {
                ship = _game.Ships.CreateCombatShip(Keys.S, AI.Team, AI.TeamColour, launchBase.SectorId);
            }
            else
            {
                ship = _game.Ships.CreateCombatShip(AI.Team, AI.TeamColour, launchBase.SectorId);
            }
            if (ship == null)
            {
                return(false);
            }

            ship.CenterX = launchBase.CenterX;
            ship.CenterY = launchBase.CenterY;

            var pos = launchBase.GetNextBuildPosition();

            ship.ShipEvent += _shipHandler;
            ship.OrderShip(new MoveOrder(_game, launchBase.SectorId, pos, Point.Empty));

            IncludedShips.Add(ship);
            _game.LaunchShip(ship);
            return(true);
        }
コード例 #6
0
        public virtual void UpdateMission()
        {
            IncludedShips.RemoveAll(_ => !_.Active);
            var cutOffTime = DateTime.Now.AddSeconds(_recentOrderDelaySecs);

            RecentOrders.RemoveAll(_ => _ > cutOffTime);

            var stillCompleted = MissionComplete();

            if (stillCompleted && !_completed)
            {
                _completed = true;
                IncludedShips.ForEach(_ => _.OrderShip(new DockOrder(_game, _)));
                IncludedShips.Clear();
            }
            else if (_completed && !stillCompleted)
            {
                _completed = false;
            }
        }
コード例 #7
0
        public override bool AddMorePilots()
        {
            var launchBase = _game.ClosestSectorWithBase(AI.Team, _lastTargetSectorId);

            if (launchBase == null)
            {
                return(false);
            }

            Ship ship = null;

            // Launch at least 1 scout first, followed by our best pilotable combat ships
            if (IncludedShips.Count < 2)
            {
                ship = _game.Ships.CreateCombatShip(Keys.S, AI.Team, AI.TeamColour, launchBase.SectorId);
            }
            else
            {
                ship = _game.Ships.CreateCombatShip(AI.Team, AI.TeamColour, launchBase.SectorId);
            }
            if (ship == null)
            {
                return(false);
            }
            if (!_game.LaunchShip(ship))
            {
                return(false);
            }

            ship.CenterX = launchBase.CenterX;
            ship.CenterY = launchBase.CenterY;

            var pos = launchBase.GetNextBuildPosition();

            ship.ShipEvent += _shipHandler;
            ship.OrderShip(new MoveOrder(_game, launchBase.SectorId, pos, Point.Empty));

            IncludedShips.Add(ship);
            return(true);
        }
コード例 #8
0
        public override bool AddMorePilots()
        {
            if (_lastTargetSectorId == -1)
            {
                return(false);
            }
            var launchBase = _game.ClosestSectorWithBase(AI.Team, _lastTargetSectorId);

            if (launchBase == null)
            {
                return(false);
            }

            // Create our best combat ship
            Ship ship = _game.Ships.CreateCombatShip(AI.Team, AI.TeamColour, launchBase.SectorId);

            if (ship == null)
            {
                return(false);
            }
            if (!_game.LaunchShip(ship))
            {
                return(false);
            }

            ship.CenterX = launchBase.CenterX;
            ship.CenterY = launchBase.CenterY;

            var pos = launchBase.GetNextBuildPosition();

            ship.ShipEvent += _shipHandler;
            ship.OrderShip(new MoveOrder(_game, launchBase.SectorId, pos, Point.Empty));

            IncludedShips.Add(ship);
            return(true);
        }
コード例 #9
0
        public override void UpdateMission()
        {
            base.UpdateMission();

            var t             = AI.Team - 1;
            var possibleRocks = _game.ResourceAsteroids.Where(_ => _.Active && _.IsVisibleToTeam(t) && _.AvailableResources > 0 && !_.BeingMined).ToList();
            var ships         = _game.AllUnits.Where(_ => _.Active && _.Team == AI.Team && _.Type == EShipType.Miner && _.CurrentOrder == null).ToList();

            if (possibleRocks.Count == 0 || ships.Count == 0)
            {
                return;
            }

            var totalResourcesInSector = new int[_game.Map.Sectors.Count];
            var enemiesInSector        = new int[_game.Map.Sectors.Count];
            var friendliesInSector     = new int[_game.Map.Sectors.Count];

            foreach (var r in possibleRocks)
            {
                totalResourcesInSector[r.SectorId] += r.AvailableResources;
            }

            for (var i = 0; i < totalResourcesInSector.Length; i++)
            {
                if (totalResourcesInSector[i] == 0)
                {
                    continue;
                }
                enemiesInSector[i]    = _game.AllUnits.Count(_ => _.Active && _.IsVisibleToTeam(t) && _.Alliance != AI.Alliance && _.CanAttackShips());
                friendliesInSector[i] = _game.AllUnits.Count(_ => _.Active && _.Alliance == AI.Alliance && _.CanAttackShips());
            }

            // Order our waiting miner ships into their best sector if there is no enemy presense > our own
            foreach (var s in ships)
            {
                var m = s as MinerShip;
                if (m == null || m.CurrentOrder != null)
                {
                    continue;
                }
                if (!IncludedShips.Contains(m))
                {
                    IncludedShips.Add(m);
                }

                var bestScore     = float.MaxValue;
                var bestSectorId  = -1;
                var startSectorId = s.SectorId;

                for (var i = 0; i < totalResourcesInSector.Length; i++)
                {
                    if (totalResourcesInSector[i] == 0 || enemiesInSector[i] > friendliesInSector[i])
                    {
                        continue;
                    }

                    var path    = _game.Map.ShortestPath(AI.Team, startSectorId, i);
                    var newHops = path == null ? int.MaxValue : path.Count();

                    var score = newHops + enemiesInSector[i] - friendliesInSector[i] - (1f * totalResourcesInSector[i] / ResourceAsteroid.MaxResources);
                    if (score < bestScore)
                    {
                        bestScore    = score;
                        bestSectorId = i;
                    }
                }

                if (bestSectorId == -1)
                {
                    m.OrderShip(new DockOrder(_game, m));
                    LogOrder();
                }
                else if (m.SectorId != bestSectorId)
                {
                    m.OrderShip(new NavigateOrder(_game, m, bestSectorId));
                    LogOrder();
                }
                else
                {
                    m.OrderShip(new MineOrder(_game, bestSectorId, _centerPos, PointF.Empty));
                    LogOrder();
                }
            }
        }
コード例 #10
0
        public override void UpdateMission()
        {
            base.UpdateMission();
            if (_completed)
            {
                return;
            }

            _checkForNewTarget--;
            if (_checkForNewTarget < 0)
            {
                CheckForNewTarget();
            }
            if (_targetBase == null)
            {
                return;
            }

            var firstBomber = IncludedShips.FirstOrDefault(_ => _.Active && _.CanAttackBases());

            foreach (var i in IncludedShips)
            {
                if (i.CurrentOrder != null)
                {
                    continue;
                }
                var append = false;

                if (!i.CanAttackBases())
                {
                    // Other ships: Dock if no more bombers
                    if (firstBomber == null)
                    {
                        i.OrderShip(new DockOrder(_game, i));
                        LogOrder();
                        continue;
                    }

                    // Get to the bomber's sector
                    if (i.SectorId != firstBomber.SectorId)
                    {
                        i.OrderShip(new NavigateOrder(_game, i, _targetBase.SectorId));
                        LogOrder();
                        append = true;
                    }

                    // Follow the bomber
                    i.OrderShip(new MoveOrder(_game, firstBomber.SectorId, firstBomber.CenterPoint), append);
                    LogOrder();
                }
                else
                {
                    // Bombers and escorts: Aim to surround the base!

                    if (i.SectorId != _targetBase.SectorId)
                    {
                        i.OrderShip(new NavigateOrder(_game, i, _targetBase.SectorId));
                        LogOrder();
                        append = true;
                    }

                    var currentAngle   = StrategyGame.Random.Next(360);
                    var angleAsRadians = (currentAngle * Math.PI) / 180.0;
                    var x = _targetBase.CenterX + Math.Cos(angleAsRadians) * DistanceFromCenter;
                    var y = _targetBase.CenterY + Math.Sin(angleAsRadians) * DistanceFromCenter;

                    i.OrderShip(new MoveOrder(_game, _targetBase.SectorId, new PointF((float)x, (float)y)), append);
                    LogOrder();
                }
            }
        }