Example #1
0
        public static BuildList Nexus(int total)
        {
            BuildList result = new BuildList();

            result += new BuildingStep(UnitTypes.NEXUS, total);

            return(result);
        }
Example #2
0
        public static BuildList Nexus(int total, ConditionalStep.Test test)
        {
            BuildList result = new BuildList();

            result += new ConditionalStep(test);
            result += new BuildingStep(UnitTypes.NEXUS, total);

            return(result);
        }
Example #3
0
        public static BuildList Pylons()
        {
            BuildList result = new BuildList();

            result.If(() =>
            {
                return(Build.FoodUsed()
                       + Tyr.Bot.UnitManager.Count(UnitTypes.NEXUS)
                       + Tyr.Bot.UnitManager.Count(UnitTypes.GATEWAY) * 2
                       + Tyr.Bot.UnitManager.Count(UnitTypes.STARGATE) * 2
                       + Tyr.Bot.UnitManager.Count(UnitTypes.ROBOTICS_FACILITY) * 2
                       >= Build.ExpectedAvailableFood() - 2);
            });
            result += new BuildingStep(UnitTypes.PYLON);
            result.Goto(0);

            return(result);
        }
Example #4
0
        private bool Construct(BuildingStep building, int number)
        {
            for (int i = 0; i < number; i++)
            {
                bool isCenter = UnitTypes.ResourceCenters.Contains(building.UnitType);

                if (Tyr.Bot.Minerals() < BuildingType.LookUp[building.UnitType].Minerals - (UnitTypes.ResourceCenters.Contains(building.UnitType) ? 75 : 25) ||
                    Tyr.Bot.Gas() < BuildingType.LookUp[building.UnitType].Gas - 16)
                {
                    Tyr.Bot.DrawText("Not enough resources for " + UnitTypes.LookUp[building.UnitType].Name + ".");
                    return(false);
                }

                if (building.DesiredPos == null && building.DesiredBase == null)
                {
                    BuiltThisFrame = true;
                    if (!Build.Construct(building.UnitType))
                    {
                        return(false);
                    }
                }
                else if (building.DesiredPos == null)
                {
                    BuiltThisFrame = true;
                    if (!Build.Construct(building.UnitType, building.DesiredBase))
                    {
                        return(false);
                    }
                }
                else
                {
                    BuiltThisFrame = true;
                    if (!Build.Construct(building.UnitType, building.DesiredBase, building.DesiredPos, building.Exact))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #5
0
        private bool Construct(BuildingStep building, int number)
        {
            for (int i = 0; i < number; i++)
            {
                bool isCenter = UnitTypes.ResourceCenters.Contains(building.UnitType);

                if (Tyr.Bot.Minerals() < BuildingType.LookUp[building.UnitType].Minerals - (UnitTypes.ResourceCenters.Contains(building.UnitType) ? 75 : 25) ||
                    Tyr.Bot.Gas() < BuildingType.LookUp[building.UnitType].Gas - 16)
                {
                    Tyr.Bot.DrawText("Not enough resources for " + UnitTypes.LookUp[building.UnitType].Name + ".");
                    return(false);
                }

                if (UnitTypes.GasGeysers.Contains(building.UnitType))
                {
                    if (Tyr.Bot.BaseManager.AvailableGasses == 0)
                    {
                        return(true);
                    }
                    if (building.DesiredBase != null)
                    {
                        bool available = false;
                        foreach (Gas gas in building.DesiredBase.BaseLocation.Gasses)
                        {
                            if (gas.Available)
                            {
                                available = true;
                                break;
                            }
                        }
                        if (!available)
                        {
                            return(true);
                        }
                    }
                }

                if (building.DesiredPos == null && building.DesiredBase == null)
                {
                    BuiltThisFrame = true;
                    if (!Build.Construct(building.UnitType))
                    {
                        return(false);
                    }
                }
                else if (building.DesiredPos == null)
                {
                    BuiltThisFrame = true;
                    if (!Build.Construct(building.UnitType, building.DesiredBase))
                    {
                        return(false);
                    }
                }
                else
                {
                    BuiltThisFrame = true;
                    if (!Build.Construct(building.UnitType, building.DesiredBase, building.DesiredPos, building.Exact))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #6
0
        public bool Construct()
        {
            BuiltThisFrame = false;
            Dictionary <uint, int>           desired        = new Dictionary <uint, int>();
            Dictionary <BuildingAtBase, int> desiredPerBase = new Dictionary <BuildingAtBase, int>();

            for (int pos = 0; pos < Steps.Count; pos++)
            {
                BuildStep step = null;
                try
                {
                    step = Steps[pos];
                    if (step.GetType() == typeof(BuildingStep))
                    {
                        BuildingStep building = (BuildingStep)step;
                        if (!building.Condition.Invoke())
                        {
                            continue;
                        }

                        if (UnitTypes.LookUp[building.UnitType].TechRequirement != 0 &&
                            Tyr.Bot.UnitManager.Completed(UnitTypes.LookUp[building.UnitType].TechRequirement) == 0 &&
                            UnitTypes.LookUp[building.UnitType].TechRequirement != UnitTypes.HATCHERY)
                        {
                            Tyr.Bot.DrawText("Skipping list. Build tech for " + UnitTypes.LookUp[building.UnitType].Name + " not available: " + UnitTypes.LookUp[building.UnitType].TechRequirement);
                            return(true);
                        }

                        Add(desired, building.UnitType, building.Number);
                        if (building.Exact)
                        {
                            bool built = false;
                            foreach (BuildRequest request in ConstructionTask.Task.BuildRequests)
                            {
                                if (request.Type == building.UnitType && SC2Util.DistanceSq(request.Pos, building.DesiredPos) <= 2)
                                {
                                    built = true;
                                    break;
                                }
                            }
                            foreach (BuildRequest request in ConstructionTask.Task.UnassignedRequests)
                            {
                                if (request.Type == building.UnitType && SC2Util.DistanceSq(request.Pos, building.DesiredPos) <= 2)
                                {
                                    built = true;
                                    break;
                                }
                            }
                            if (!built)
                            {
                                foreach (Agent agent in Tyr.Bot.UnitManager.Agents.Values)
                                {
                                    if (agent.Unit.UnitType == building.UnitType && SC2Util.DistanceSq(agent.Unit.Pos, building.DesiredPos) <= 2)
                                    {
                                        built = true;
                                        break;
                                    }
                                }
                            }
                            if (!built)
                            {
                                if (!Construct(building, 1))
                                {
                                    return(false);
                                }
                            }
                        }

                        if (building.DesiredBase == null && desired[building.UnitType] > Tyr.Bot.UnitManager.Count(building.UnitType) &&
                            !building.Exact)
                        {
                            if (!Construct(building, desired[building.UnitType] - Tyr.Bot.UnitManager.Count(building.UnitType)))
                            {
                                return(false);
                            }
                        }
                        if (building.DesiredBase != null)
                        {
                            BuildingAtBase key = new BuildingAtBase(building.UnitType, building.DesiredBase);
                            Add(desiredPerBase, key, building.Number);

                            if (desiredPerBase[key] > Build.Count(building.DesiredBase, building.UnitType) &&
                                !building.Exact)
                            {
                                Tyr.Bot.DrawText("Building " + UnitTypes.LookUp[building.UnitType].Name + " at base.");
                                if (!Construct(building, desiredPerBase[key] - Build.Count(building.DesiredBase, building.UnitType)))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    else if (step.GetType() == typeof(ConditionalStep))
                    {
                        if (!((ConditionalStep)step).Check())
                        {
                            Tyr.Bot.DrawText("Skipping list. Condition not met.");
                            return(true);
                        }
                    }
                    else if (step.GetType() == typeof(GotoStep))
                    {
                        if (BuiltThisFrame)
                        {
                            return(true);
                        }
                        if (((GotoStep)step).Pos < 0)
                        {
                            pos += ((GotoStep)step).Pos;
                        }
                        else
                        {
                            pos = ((GotoStep)step).Pos - 1;
                        }
                    }
                    if (step.GetType() == typeof(MorphStep))
                    {
                        MorphStep morph = (MorphStep)step;
                        if (!morph.Condition.Invoke())
                        {
                            continue;
                        }

                        if (UnitTypes.LookUp[morph.UnitType].TechRequirement != 0 &&
                            Tyr.Bot.UnitManager.Completed(UnitTypes.LookUp[morph.UnitType].TechRequirement) == 0 &&
                            UnitTypes.LookUp[morph.UnitType].TechRequirement != UnitTypes.HATCHERY)
                        {
                            Tyr.Bot.DrawText("Skipping list. Morph tech for " + UnitTypes.LookUp[morph.UnitType].Name + " not available: " + UnitTypes.LookUp[morph.UnitType].TechRequirement);
                            return(true);
                        }

                        Add(desired, morph.UnitType, morph.Number);

                        if (desired[morph.UnitType] > Tyr.Bot.UnitManager.Count(morph.UnitType))
                        {
                            if (!Morph(morph, desired[morph.UnitType] - Tyr.Bot.UnitManager.Count(morph.UnitType)))
                            {
                                return(false);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Exception in buildlist at step " + pos + ": " + step, e);
                }
            }
            return(true);
        }