Beispiel #1
0
        private bool ProducedMorphed(ProductionOrder order)
        {
            IUnit target = null;
            var   ids    = techTree.GetProducersID(order.Unit);

            if (IsStructure(ids.First()))
            {
                target = intelManager.StructuresSelf(ids).FirstOrDefault(u => u.Orders.Count == 0);
            }
            else
            {
                target = intelManager.UnitsSelf(ids).FirstOrDefault(u => u.Orders.Count == 0);
            }
            if (target == null || !ReserveRessource(order.Unit, false))
            {
                return(false);
            }
            ;
            target.Orders.Add(new UnitOrder {
            });
            if (target.UnitType == BlizzardConstants.Unit.Larva)
            {
                order.Status = ProductionOrder.OrderStatus.Commissioned;
            }
            else
            {
                order.Status      = ProductionOrder.OrderStatus.Producing;
                order.OrderedUnit = target;
            }
            order.AssignedUnit = target;
            rawManager.QueueActions(RawCommand(order.Unit.AbilityId, order.AssignedUnit.Tag));
            return(true);
        }
Beispiel #2
0
        public void OnStep()
        {
            if (_intelManager.GameLoop % 250 == 0 && _done)
            {
                KillEverything();
            }
            if (_intelManager.ProductionQueue.Any())
            {
                return;
            }
            if (_done)
            {
                return;
            }

            foreach (var crook in _intelManager.UnitsSelf())
            {
                gang.AddUnit(crook);
            }
            foreach (var colony in _eStarts)
            {
                _combatManager.AttackMove(gang, colony.Point, true);
            }
            _done = true;
            Console.WriteLine("Queue'ing them up");
            QueueThemUp();
        }
Beispiel #3
0
 public void OnAdded()
 {
     OnStart();
     foreach (var crook in _intelManager.UnitsSelf())
     {
         if (crook.UnitType != BlizzardConstants.Unit.Overlord)
         {
             _theGang.AddUnit(crook);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Called on the first frame of every game.
        /// </summary>
        public void OnStart()
        {
            if (_startCalled)
            {
                return;
            }

            // Colonies marked with Starting location are possible starting locations of the enemy NOT yourself
            _eStarts = _intelManager.Colonies.Where(c => c.IsStartingLocation);

            // Queue a hardcoded all-in
            QueueOneBaseRavager();

            // Using the AutoHarvestGather module DesiredVespeneWorkers decides how many workers will be assigned to gather vespene
            // Without AutoHarvestGather in the setup.json file (or and alternative) this has no effect
            _intelManager.PrimaryColony.DesiredVespeneWorkers = 4;

            // Creating a squad allows for treating a group of units as one.
            // The name allows other modules to look it up by name! (as IDs are generated at runtime)
            _theGang = _squadRep.Create("TheGang");

            // Include workers in our squad!
            foreach (var crook in _intelManager.UnitsSelf())
            {
                if (crook.UnitType != BlizzardConstants.Unit.Overlord)
                {
                    _theGang.AddUnit(crook);
                }
            }

            // The _intelManager.Handler allows for actions to be carried out when specific events happens.
            // Registering a handler to a Case means the handler will be called every time the event happens.
            _intelManager.Handler.RegisterHandler(Case.UnitAddedSelf, UnitCreationHandler);
            _intelManager.Handler.RegisterHandler(Case.StructureAddedSelf, s =>
            {
                if (s.UnitType == BlizzardConstants.Unit.RoachWarren)
                {
                    // Increase vespene workers after the roach warren is added!
                    _intelManager.PrimaryColony.DesiredVespeneWorkers = 6;
                }
            });

            // A variable needed since ZergDemo is a replaceable module relying on its on OnStart, but dont want it to be called twice
            _startCalled = true;
            _attackMode  = false;
        }
Beispiel #5
0
 public bool HasUnit(uint id)
 {
     if (GameConstants.IsWorker(id) || GameConstants.IsLarva(id))
     {
         return(true);
     }
     if (id == BlizzardConstants.Unit.Hatchery)
     {
         return(intelManager.StructuresSelf().Any(u => (u.UnitType == id || u.UnitType == BlizzardConstants.Unit.Lair || u.UnitType == BlizzardConstants.Unit.Hive) && u.BuildProgress == 1f));
     }
     if (id == BlizzardConstants.Unit.Lair)
     {
         return(intelManager.StructuresSelf().Any(u => (u.UnitType == id || u.UnitType == BlizzardConstants.Unit.Hive) && u.BuildProgress == 1f));
     }
     return(intelManager.StructuresSelf().Any(u => u.UnitType == id && u.BuildProgress == 1f) || intelManager.UnitsSelf().Any(u => u.UnitType == id));
 }
Beispiel #6
0
        public void OnStep()
        {
            snapshot.UpdateState(intelManager);

            if (intelManager.GameLoop % 100 == 0)
            {
                Console.WriteLine("Attacking: " + snapshot.Attacking);
                Helpers.PrintProductionQueue(intelManager);
                activeTactics.ForEach(t => Console.WriteLine(t.GetType().Name));
            }

            // 0. Build basic econ and defense
            startupSequenceDone = CheckStartupDone();

            // 1. Assess threats? (10%)
            var ownUnitCount   = intelManager.UnitsSelf().Count();
            var enemyUnitCount = intelManager.UnitsEnemy().Count();

            if (snapshot.BaseThreats.Sum(kv => kv.Value.Count) > (0.1 * ownUnitCount))
            {
                snapshot.Attacking   = false;
                snapshot.EconomyMode = EconomyMode.Standby;
            }
            else if (ownUnitCount > enemyUnitCount * 1.2)
            {
                snapshot.Attacking   = true;
                snapshot.EconomyMode = EconomyMode.Expand;
            }
            else
            {
                snapshot.Attacking   = false; // Build up as default
                snapshot.EconomyMode = EconomyMode.Expand;
            }

            // 2. Coordinate modules
            if (intelManager.StructuresSelf(BlizzardConstants.Unit.Barracks).Any() &&
                !IsTacticActive(typeof(InfantryModule)))
            {
                AddTactic(new InfantryModule(snapshot, intelManager, productionManager, combatManager, squadRepo));
            }

            if (startupSequenceDone)
            {
                if (!infantryUpgraded)
                {
                    QueueInfantryUpgrades();
                    infantryUpgraded = true;
                }

                if (intelManager.GameLoop > 900 && // 1 m 30 sec?
                    !IsTacticActive(typeof(MechModule)))
                {
                    AddTactic(new MechModule(snapshot, intelManager, productionManager, combatManager, squadRepo));
                }

                if (intelManager.GameLoop > 3000 && // 5 m?
                    !IsTacticActive(typeof(AirModule)))
                {
                    AddTactic(new AirModule(snapshot, intelManager, productionManager, combatManager, squadRepo));
                }
            }

            // 3. Try to be ahead on supply
            if (snapshot.RemainingSupply < 10 && !IsBuildingSupplyDepot())
            {
                productionManager.QueueUnit(BlizzardConstants.Unit.SupplyDepot, lowPriority: true,
                                            desiredPosition: snapshot.LeastExpandedColony.Point);
            }
        }
Beispiel #7
0
        public IntelResponse BundleIntel(IntelRequest request)
        {
            AbathurMap map = null;

            if (request.Map)
            {
                map = new AbathurMap {
                }
            }
            ;
            Score score = null;

            if (request.Score)
            {
                score = _intel.CurrentScore;
            }
            PlayerCommon playerCommon = null;

            if (request.Common)
            {
                playerCommon = _intel.Common;
            }
            ICollection <UpgradeData> upgradeSelf = null;

            if (request.UpgradesSelf)
            {
                upgradeSelf = _intel.UpgradesSelf;
            }
            ICollection <IUnit> alliedBuilding = null;

            if (request.BuildingsSelf)
            {
                alliedBuilding = _intel.StructuresSelf().ToList();
            }
            ICollection <IUnit> alliedWorkers = null;

            if (request.WorkersSelf)
            {
                alliedWorkers = _intel.WorkersSelf().ToList();
            }
            ICollection <IUnit> alliedUnits = null;

            if (request.WorkersSelf)
            {
                alliedUnits = _intel.UnitsSelf().ToList();
            }
            ICollection <IUnit> structuresEnemy = null;

            if (request.StructuresEnemy)
            {
                structuresEnemy = _intel.WorkersEnemy().ToList();
            }
            ICollection <IUnit> unitsEnemy = null;

            if (request.UnitsEnemy)
            {
                unitsEnemy = _intel.WorkersEnemy().ToList();
            }
            ICollection <IUnit> workersEnemy = null;

            if (request.WorkersEnemy)
            {
                workersEnemy = _intel.WorkersEnemy().ToList();
            }
            IColony primaryColony = null;

            if (request.PrimaryColony)
            {
                primaryColony = _intel.PrimaryColony;
            }
            IEnumerable <IColony> colonies = null;

            if (request.Colonies)
            {
                colonies = _intel.Colonies;
            }
            ICollection <IUnit> mineralFields = null;

            if (request.MineralFields)
            {
                mineralFields = _intel.MineralFields.ToList();
            }
            ICollection <IUnit> vespeneGeysers = null;

            if (request.VespeneGeysers)
            {
                vespeneGeysers = _intel.VespeneGeysers.ToList();
            }
            ICollection <IUnit> destructibles = null;

            if (request.Destructibles)
            {
                destructibles = _intel.Destructibles().ToList();
            }
            ICollection <UnitTypeData> productionQueue = null;

            if (request.ProductionQueue)
            {
                productionQueue = _intel.ProductionQueue.ToList();
            }
            IEnumerable <Squad> squads = null;

            if (request.Squads)
            {
                squads = _squadRepo.Get();
            }
            uint gameloop = 0;

            if (request.GameLoop)
            {
                gameloop = _intel.GameLoop;
            }

            return(new IntelResponse {
                Map = map,
                Score = score,
                Common = playerCommon,
                UpgradesSelf = { upgradeSelf },
                BuildingsSelf = { Convert(alliedBuilding) },
                WorkersSelf = { Convert(alliedWorkers) },
                UnitsSelf = { Convert(alliedUnits) },
                StructuresEnemy = { Convert(structuresEnemy) },
                WorkersEnemy = { Convert(workersEnemy) },
                UnitsEnemy = { Convert(unitsEnemy) },
                PrimaryColony = Convert(primaryColony),
                Colonies = { Convert(colonies.ToList()) },
                MineralFields = { Convert(mineralFields) },
                VespeneGeysers = { Convert(vespeneGeysers) },
                Destructibles = { Convert(destructibles) },
                ProductionQueue = { productionQueue },
                Squads = { squads.Select(Convert) },
                GameLoop = gameloop
            });
        }