Exemplo n.º 1
0
        public override void Update()
        {
            if (!Enabled)
            {
                return;
            }
            _nextActionAllowed--;
            if (_nextActionAllowed > 0)
            {
                return;
            }

            UpdatePriorities();
            UpdateCheats();

            var idleShips = _game.AllUnits.Where(_ => _.Active && !_.Docked && _.Team == Team && _.CurrentOrder == null && _.Type != EShipType.Constructor && _.Type != EShipType.Miner && _.Type != EShipType.Lifepod).ToList();

            // Add more pilots to missions
            foreach (var v in PilotPriorities.OrderByDescending(_ => _.Value))
            {
                if (v.Value < MinActionAmount)
                {
                    break;
                }

                switch (v.Key)
                {
                case EAiPilotPriorities.Scout:
                    if (Scouting && _scouting.RequireMorePilots())
                    {
                        _scouting.AddMorePilots();
                    }
                    break;

                case EAiPilotPriorities.BaseOffense:
                    if (BaseOffence && _bombing.RequireMorePilots())
                    {
                        _bombing.AddMorePilots();
                        if (idleShips.Count > 0)
                        {
                            _bombing.IncludedShips.AddRange(idleShips);
                            idleShips.Clear();
                        }
                    }
                    break;

                case EAiPilotPriorities.MinerOffense:
                    if (MinerOffence && _minerO.RequireMorePilots())
                    {
                        _minerO.AddMorePilots();
                        if (idleShips.Count > 0)
                        {
                            _bombing.IncludedShips.AddRange(idleShips);
                            idleShips.Clear();
                        }
                    }
                    break;

                case EAiPilotPriorities.BaseDefense:
                    if (BaseDefence && _defense.RequireMorePilots())
                    {
                        _defense.AddMorePilots();
                    }
                    break;

                case EAiPilotPriorities.MinerDefense:
                    if (MinerDefence && _minerD.RequireMorePilots())
                    {
                        _minerD.AddMorePilots();
                    }
                    break;
                }
            }
            UpdateMissions();

            // Control purchases
            if (CreditsForExpansion || CreditsForDefence || CreditsForOffence)
            {
                var c = CreditPriorities
                        .Where(_ => (_.Key == EAiCreditPriorities.Expansion && CreditsForExpansion) ||
                               (_.Key == EAiCreditPriorities.Offense && CreditsForOffence) ||
                               (_.Key == EAiCreditPriorities.Defense && CreditsForDefence))
                        .OrderByDescending(_ => _.Value).FirstOrDefault();
                if (!Utils.IsDefault(c))
                {
                    var tech  = _game.TechTree[_t].ResearchableItemsNot(ETechType.Construction).OrderByDescending(_ => _.Id).ToList();
                    var cons  = _game.TechTree[_t].ResearchableItems(ETechType.Construction).OrderByDescending(_ => _.Id).ToList();
                    var funds = _game.Credits[_t];

                    var hasExpTech = Bases.Any(_ => _.Active && _.Team == Team && _.Type == EBaseType.Expansion);
                    var hasSupTech = Bases.Any(_ => _.Active && _.Team == Team && _.Type == EBaseType.Supremacy);
                    var hasTacTech = Bases.Any(_ => _.Active && _.Team == Team && _.Type == EBaseType.Tactical);
                    var hasCapTech = Bases.Any(_ => _.Active && _.Team == Team && _.Type == EBaseType.Shipyard);

                    if (funds > 0)
                    {
                        NextTech = null;
                        if (c.Key == EAiCreditPriorities.Expansion)
                        {
                            NextTech = cons.FirstOrDefault(_ => _.CanBuild() && _.AmountInvested < _.Cost);
                        }
                        if (c.Key == EAiCreditPriorities.Offense || (c.Key == EAiCreditPriorities.Expansion && NextTech == null))
                        {
                            NextTech = tech.FirstOrDefault(_ => _.Name.Contains("Bomber") && _.AmountInvested < _.Cost &&
                                                           ((_.Type == ETechType.Starbase) ||
                                                            (_.Type == ETechType.Tactical && hasTacTech) ||
                                                            (_.Type == ETechType.Expansion && hasExpTech) ||
                                                            (_.Type == ETechType.Supremacy && hasSupTech)
                                                           ));
                        }
                        if (c.Key == EAiCreditPriorities.Defense || NextTech == null)
                        {
                            NextTech = tech.FirstOrDefault(_ => !_.Name.Contains("Bomber") && _.AmountInvested < _.Cost &&
                                                           ((_.Type == ETechType.Starbase) ||
                                                            (_.Type == ETechType.ShipyardConstruction && hasCapTech && _.CanBuild()) ||
                                                            (_.Type == ETechType.Supremacy && hasSupTech) ||
                                                            (_.Type == ETechType.Tactical && hasTacTech) ||
                                                            (_.Type == ETechType.Expansion && hasExpTech)
                                                           ));
                        }

                        if (NextTech != null)
                        {
                            var invested = _game.SpendCredits(Team, NextTech.Cost);
                            NextTech.AmountInvested += invested;
                        }
                    }
                }
            }

            _nextActionAllowed = _limitActionsTickDelay;
        }
Exemplo n.º 2
0
        private void UpdateMissions()
        {
            _mining.UpdateMission();
            _minerOffense.UpdateMission();
            _baseOffense.UpdateMission();
            _building.UpdateMission();
            _scouting.UpdateMission();
            _minerDefense.UpdateMission();
            _baseDefense.UpdateMission();

            var stillAddingPilots = true;
            var idleShips         = _game.AllUnits.Where(_ => _.Active && !_.Docked && _.Team == Team && _.CurrentOrder == null && _.Type != EShipType.Constructor && _.Type != EShipType.Miner && _.Type != EShipType.Lifepod).ToList();

            if (_game.DockedPilots[_t] == 0 && idleShips.Count == 0)
            {
                return;
            }

            if (!_flagHaveBombers)
            {
                _flagHaveBombers = _flagHaveBombers || _game.TechTree[_t].HasResearchedShipType(EShipType.Bomber);
            }
            if (!_flagFoundEnemyBase)
            {
                _flagFoundEnemyBase = _flagFoundEnemyBase || _game.AllBases.Exists(_ => _.IsVisibleToTeam(_t) && _.Active && _.Alliance != Alliance);
            }
            if (!_flagBuiltTech)
            {
                _flagBuiltTech = _flagBuiltTech || _game.AllBases.Exists(_ => _.Active && _.Team == Team && _.IsTechBase());
            }
            if (!_flagBuiltFocusTech)
            {
                _flagBuiltFocusTech = _flagBuiltFocusTech || _game.AllBases.Exists(_ => _.Active && _.Team == Team && _.Type.ToString() == _initTechName);
            }

            _flagFoundEnemyBombers = _game.AllUnits.Exists(_ => _.Active && _.IsVisibleToTeam(_t) && _.Alliance != Alliance && _.CanAttackBases());

            if (_flagFoundEnemyBombers)
            {
                if (_game.DockedPilots[_t] == 0)
                {
                    _minerDefense.ReducePilots(0.75f);
                    _baseOffense.ReducePilots(0.25f);
                }

                if (idleShips.Count > 0)
                {
                    _baseDefense.IncludedShips.AddRange(idleShips);
                    idleShips.Clear();
                }

                stillAddingPilots = true;
                while (stillAddingPilots && _game.DockedPilots[_t] > 0 && _baseDefense.RequireMorePilots())
                {
                    stillAddingPilots = _baseDefense.AddMorePilots();
                }
            }

            if (_flagHaveBombers && _flagFoundEnemyBase)
            {
                if (idleShips.Count > 0)
                {
                    _baseOffense.IncludedShips.AddRange(idleShips);
                    idleShips.Clear();
                }

                while (stillAddingPilots && _game.DockedPilots[_t] > 0 && _baseOffense.RequireMorePilots())
                {
                    stillAddingPilots = _baseOffense.AddMorePilots();
                }
            }

            if (_flagFoundEnemyBase)
            {
                if (_game.DockedPilots[_t] == 0)
                {
                    _minerDefense.ReducePilots(0.75f);
                }
                if (idleShips.Count > 0)
                {
                    _minerOffense.IncludedShips.AddRange(idleShips);
                    idleShips.Clear();
                }

                stillAddingPilots = true;
                while (stillAddingPilots && _game.DockedPilots[_t] > 0 && _minerOffense.RequireMorePilots())
                {
                    stillAddingPilots = _minerOffense.AddMorePilots();
                }
            }

            stillAddingPilots = true;
            while (stillAddingPilots && _game.DockedPilots[_t] > 0 && _scouting.RequireMorePilots())
            {
                stillAddingPilots = _scouting.AddMorePilots();
            }

            if (_building.IncludedShips.Count > 0 || _mining.IncludedShips.Count > 0)
            {
                stillAddingPilots = true;
                while (stillAddingPilots && _game.DockedPilots[_t] > 0 && _minerDefense.RequireMorePilots())
                {
                    stillAddingPilots = _minerDefense.AddMorePilots();
                }
            }
        }