Esempio n. 1
0
        public VariantAI(StrategyGame game, int team, Color teamColour, Ship.ShipEventHandler shipHandler) : base(game, team, teamColour, shipHandler)
        {
            _scouting     = new ScoutingMission(game, this, _shipHandler);
            _minerOffense = new MinerOffenseMission(game, this, shipHandler);
            _mining       = new MinerMission(game, this, shipHandler);
            _building     = new BuilderMission(game, this, shipHandler);
            _baseOffense  = new BombingMission(game, this, shipHandler);
            _minerDefense = new MinerDefenseMission(game, this, shipHandler);
            _baseDefense  = new BaseDefenseMission(game, this, shipHandler);

            if (StrategyGame.RandomChance(0.5f))
            {
                _initTech = EInitialTargetTech.ChooseInSector;
            }
            else
            {
                _initTech = (StrategyGame.RandomChance(0.75f)) ? EInitialTargetTech.Starbase : EInitialTargetTech.Shipyard;
            }

            _focusBuildOrder = StrategyGame.RandomChance(0.95f);

            // Play test a specific focus:
            //_initTech = EInitialTargetTech.Shipyard;
            //_focusBuildOrder = true;

            _initTechName = Enum.GetName(typeof(EInitialTargetTech), _initTech);
        }
Esempio n. 2
0
        private void UpdateFocussedBuildOrder()
        {
            // Focus on miners, outpost, random tech, garrison, refinery. Then main tech upgrades and bombers, then other random building and research.
            if (_game.Credits[_t] <= 100)
            {
                return;
            }

            if (_initTech == EInitialTargetTech.ChooseInSector)
            {
                var startingSector = _game.AllBases.First(_ => _.Team == Team && _.Type == EBaseType.Starbase).SectorId;
                var techRocks      = _game.AllAsteroids.Where(_ => _.SectorId == startingSector && _.Active && !(_.Type == EAsteroidType.Generic || _.Type == EAsteroidType.Resource)).ToList();
                var choice         = StrategyGame.RandomItem(techRocks);

                switch (choice.Type)
                {
                case EAsteroidType.Carbon:
                    _initTech = EInitialTargetTech.Supremacy;
                    break;

                case EAsteroidType.Silicon:
                    _initTech = EInitialTargetTech.Tactical;
                    break;

                case EAsteroidType.Uranium:
                    _initTech = EInitialTargetTech.Expansion;
                    break;

                default:
                    _initTech = EInitialTargetTech.Starbase;
                    break;
                }

                _initTechName = Enum.GetName(typeof(EInitialTargetTech), _initTech);
            }

            var ourSectors = (from b in _game.AllBases
                              where b.Active && b.Team == Team && b.CanLaunchShips()
                              select b.SectorId).Distinct().ToList();

            // If we have money, build resources
            if (_game.Credits[_t] > 1000)
            {
                var resourcesToBuild = (from c in _game.TechTree[_t].ResearchableItems(ETechType.Construction)
                                        where c.CanBuild() && c.AmountInvested < c.Cost &&
                                        (c.Name.Contains("Miner") ||
                                         c.Name.Contains("Resource"))
                                        select c).ToList();
                TryToInvestInResources(resourcesToBuild, ourSectors);
            }

            // Expand & Build Randomly our focus tech:
            var basesToBuild = (from c in _game.TechTree[_t].ResearchableItems(ETechType.Construction)
                                where c.CanBuild() && c.AmountInvested < c.Cost &&
                                (c.Name.Contains("Outpost") ||
                                 c.Name.Contains("Starbase") ||
                                 c.Name.Contains(_initTechName))
                                orderby c.Id descending
                                select c).ToList();

            TryToInvestInBases(basesToBuild, ourSectors);

            // Once we have built our tech, research it randomly along with bombers/drones
            if (!_flagBuiltFocusTech)
            {
                return;
            }

            var tech = (from t in _game.TechTree[_t].ResearchableItemsNot(ETechType.Construction)
                        where t.CanBuild() &&
                        (int)t.Type == (int)_initTech &&
                        t.AmountInvested < t.Cost
                        orderby t.Cost - t.AmountInvested, t.Id descending
                        select t).Take(3).ToList();

            var bbr = (from t in _game.TechTree[_t].TechItems
                       where t.Active &&
                       !t.Completed &&
                       (t.Name.Contains("Bomber") || t.Name.Contains("Combat Drones"))
                       select t).FirstOrDefault();

            if (bbr != null)
            {
                tech.Add(bbr);
            }

            InvestInRandomTech(tech);

            // Once we are done with our focus, branch out!
            if (tech.Count() < 2)
            {
                _focusBuildOrder = false;
            }
        }