Exemple #1
0
        void EventForCreatingAnother()
        {
            GameEvent.Register(GameEventType.MineralsChanged, argsA =>
            {
                if (_producingWorker == null && argsA.Minerals >= 50)
                {
                    // After he collected minerals, another worker will be built
                    var baseCenter = BuildingHelper.GetMyBuildings <BaseCenter>()[0];
                    baseCenter.ProduceUnit(UnitType.Worker);

                    // After creating (it means after few seconds), he will need to go gather too
                    _producingWorker = GameEvent.Register(GameEventType.UnitProduced, argsB =>
                    {
                        if (argsB.MyUnit is Worker)
                        {
                            Worker worker = (Worker)argsB.MyUnit;
                            Gather(worker);
                            argsB.ThisGameEvent.UnregisterEvent();
                            _producingWorker = null;
                        }
                    });
                }

                // This event will work only while there are not enough workers.
                // After that, minerals will be left to go over 150.
                if (UnitHelper.GetMyUnits <Worker>().Length >= 7)
                {
                    argsA.ThisGameEvent.UnregisterEvent();
                }
            });
        }
Exemple #2
0
        void WorkersCanExpand()
        {
            var baseCenter = BuildingHelper.GetMyBuildings <BaseCenter>()[0];

            if (baseCenter != null && baseCenter.CanNowProduceUnit(UnitType.Worker))
            {
                baseCenter.ProduceUnit(UnitType.Worker);
            }
            // TODO: make workers expand to other minerals over the map
            BuildingTest.FindWorkerThatGathers().MoveTo(PlaceType.MyBase.UnderRampLeft);
        }
Exemple #3
0
        public void SelfTests()
        {
            // GameManager starting Unit creation
            Assert.AreEqual(1, BuildingHelper.GetMyBuildings <IBuilding>().Length);
            Assert.AreEqual(1, BuildingHelper.GetMyBuildings <BaseCenter>().Length);
            var units = GameManager.Instance.StartingWorkers;

            Assert.AreEqual(units, UnitHelper.GetMyUnits <IUnit>().Length);
            Assert.AreEqual(units, UnitHelper.GetMyUnits <Worker>().Length);

            // Position Grid coordinate calculation Unit Test
            var center = PlaceType.MyBase.Center;

            Assert.AreEqual(center.PointLocation, new Position(center.X, center.Y).PointLocation);
        }
Exemple #4
0
 void BuildArmy(Action startNextStage)
 {
     GameEvent.Register(GameEventType.MineralsChanged, argsMinerals =>
     {
         // First wave starts at 5 units
         if (!MyBotData.Rushed && MyBotData.Army >= 5)
         {
             startNextStage();
             MyBotData.Rushed = true;
         }
         // Production ends after 20
         else if (MyBotData.Army >= 20)
         {
             argsMinerals.ThisGameEvent.UnregisterEvent();
             return;
         }
         if (_producingDonkeyGun != null || argsMinerals.Minerals <= 100)
         {
             return;
         }
         foreach (NubianArmory armory in BuildingHelper.GetMyBuildings <NubianArmory>())
         {
             if (armory.QueuedUnits >= 2)
             {
                 continue;
             }
             if (armory.CanNowProduceUnit(UnitType.DonkeyGun))
             {
                 armory.ProduceUnit(UnitType.DonkeyGun);
                 // Additional mineral sink: producing one more expensive Unit if too rich
                 if (armory.CanNowProduceUnit(UnitType.WraithRaider))
                 {
                     armory.ProduceUnit(UnitType.WraithRaider);
                 }
                 _producingDonkeyGun = GameEvent.Register(GameEventType.UnitProduced, argsUnit =>
                 {
                     if (argsUnit.MyUnit is DonkeyGun)
                     {
                         MyBotData.Army++;
                         BotRunner.Log("My army contains " + MyBotData.Army + " battle units");
                         argsUnit.ThisGameEvent.UnregisterEvent();
                         _producingDonkeyGun = null;
                     }
                 });
             }
         }
     });
 }
Exemple #5
0
        private static bool CreateBaseIfNone(Worker worker)
        {
            // If all bases were destroyed, try to make a new one
            var bases = BuildingHelper.GetMyBuildings <BaseCenter>();

            if (bases.Length == 0)
            {
                worker.CreateBuilding(
                    BuildingType.BaseCenter,
                    BuildingHelper.ClosestEmptySpaceTo(
                        BuildingHelper.GetMyBuildings <IBuilding>()[0],
                        BuildingType.BaseCenter));
                return(true);
            }
            if (!bases[0].Finished)
            {
                worker.FinishBuiding(bases[0]);
                return(true);
            }
            return(false);
        }
Exemple #6
0
        private bool BuildNubianArmory(Arguments args)
        {
            if (args.Minerals < 100)
            {
                return(false);
            }
            var baseCenter = BuildingHelper.GetMyBuildings <BaseCenter>()[0];
            var position   = BuildingHelper.ClosestEmptySpaceTo(baseCenter, BuildingType.NubianArmory);

            if (position == null)
            {
                return(false);
            }
            IBuilding building = FindWorkerThatGathers().CreateBuilding(BuildingType.NubianArmory, position);

            FindWorkerThatGathers().FinishBuiding(building);

            // We only need one army production building for now
            args.ThisGameEvent.UnregisterEvent();
            return(true);
        }