Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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();
                }
            }
        }